From 474f4b618cd5e0111779cfba0cdd3be1cc4ea9fe Mon Sep 17 00:00:00 2001 From: krahets Date: Wed, 3 Jan 2024 17:56:15 +0800 Subject: [PATCH] deploy --- .../graph_bfs_step4.png | Bin 33193 -> 33040 bytes chapter_hashing/hash_collision/index.html | 4 +- .../hello_algo_mindmap.jpg | Bin 164629 -> 0 bytes .../hello_algo_mindmap.png | Bin 0 -> 171375 bytes chapter_preface/about_the_book/index.html | 2 +- chapter_sorting/counting_sort/index.html | 2 +- chapter_tree/binary_search_tree/index.html | 30 +-- en/assets/covers/chapter_introduction.jpg | Bin 140552 -> 140830 bytes en/sitemap.xml | 54 ++--- en/sitemap.xml.gz | Bin 451 -> 451 bytes search/search_index.json | 2 +- sitemap.xml | 208 +++++++++--------- sitemap.xml.gz | Bin 998 -> 999 bytes 13 files changed, 152 insertions(+), 150 deletions(-) delete mode 100644 chapter_preface/about_the_book.assets/hello_algo_mindmap.jpg create mode 100644 chapter_preface/about_the_book.assets/hello_algo_mindmap.png diff --git a/chapter_graph/graph_traversal.assets/graph_bfs_step4.png b/chapter_graph/graph_traversal.assets/graph_bfs_step4.png index 8a6902a9c7c7a059e02b2959b05e5258edbe6778..d255fccb44957068cfec10e16dcecf2ca287350d 100644 GIT binary patch delta 32289 zcma&NWmH>jv@ROK-5rV-E$;5_E=7tKDejU$aVYNYP~4>y2t|s!dkd7}?sn+6_qo6B zxZ~#6N~S#W&Y5JajC}nJiVp_W(Stz&vq=nKEgS$*n7KYd-0{mU0lA;lAPpQ+k_4C- zl6#E?Q&hmi(*LS}u-Ul7y@Fxvd7R7R!2sC0mHLGdHDuA|9v{fo9jw$NV#`24{Tr)J zN@kE!o=S;*wP#5Nam`q8Lv1q7+08YUudAv4#%^VG^@4P{qMss7Y_}w`G=NrQYMT29 zf?vz+CNMR;*Q7nuBssLF$W``!o?FEak|GKkN-`mh67uu;(b0bK5z68=VJ|+@glV}? zyy+tut|AW(fBfd;B}p^sYq?98cR;<$l9{?LN_m8|A> zcx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2YAz2%;#kV!DCe+-% z)vjk{1YYIrqPtIAbzn)Awem~_$uOp+4;$V?sN~yx?I1y5m z%z)y}m>4G)d`QL)7=j2>PIwmfG-aB>L*cR6L|5;t(Nwd)>xPYvtr>a#ySO5G`nBr% zf`JY7S8B)JzUDCNfqs1kW3&U%tkdM}Jr|8ih`-mEGm}H4q`XAH)57-AP^vEUf;w46 z^Fvtwpmd}QjsNwQ*YXJ8(LRGIo(qqw&#kB})Ix}q+*!Lcdyi(F{P714#o}}@^c zGbbG=hkE;wgUc@w;;;6FmHm!S#EZW;4~=Y%-d~Dy>gV9nuEqY4$BW82;9|PmS$f?Q zDhk|#Q;XspW{dRn-g_nu8A4aOKiz!MMvlnx5R3Jo0x1G}YJE5E!hJKPle67@fR##@ z?U$sRzY@+0yUY|!9uS{ARj=228UHH_8`Vq~_veSa{a^_NuZF!}F7s?JRot!{=6Y&d z4td!JU}cw1W_w|T?yfH3VqA`qfh(3%3n+op^{0O7VB&SM;TINZ6V+dU_=oSP;TrlB zp}X?b@Jzq0!2>4pb4Ne z?c5gvcM1oYzlSP(_k=s{UxxqJ{h|Fq-z`mgbk_KC_vkxrk`vYrj~z3Z4{3ih9CFGu zs^E!tpXTk|gE7hH$~{Wk=nm{E4%WOqcLO(a2yL*ipB%hNYTvyc7mq`ork~HRSMD^| z{$*hw*94qK{`K;ztHDd=Z#(SolbH5h-hVqu`Pa$QSO4k+#x(g?C;Y1u{=38Y*G%|d zXF^uq>W#(FPGW+(tPLuzVM=n`P~*#nU5K#8weqEdU}W TS|ktc$ShE0dsl$v+vtA-peq;G diff --git a/chapter_preface/about_the_book.assets/hello_algo_mindmap.png b/chapter_preface/about_the_book.assets/hello_algo_mindmap.png new file mode 100644 index 0000000000000000000000000000000000000000..309488ea3a9cb02994e879240c584c599dd219dc GIT binary patch literal 171375 zcmce6Rao7<6Xx&WR-8g96nAfNFYXS-U5dNg0gAg*+}+&@2X}WrxEK3y+y3`@uQxZz zB$;F~nan(SlW-*k$qy)m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Q+K`NI`v}`s;2@=V&BCQD65D_Itu`>NrP;^U)EHJ1;w)xs%9jGI<(fDWLIRaSv=rfaAe9jGy-rfu$siGcEgI~ ztSmg*09f1wTN2<4=Q#d;$C01&H8}Z`F$P{dG>(?>F{xE4f}ZCq`}1zy2i(c_T>n;c zWR;>1@acd(jG6IXi`lsD6KD(-HaD(3;fpGD^It-_uecR9CcvU7iVu_ki=rq>fJIRh zCBUNiWv31V000001o>MJazO+F1P~yA009IDAV2^C0tgV;5+JZ8KwwLNz*g+|D z3;-d0X#dDtkAn~h5XcfBkR?DMOMpO@0D&w40$BnCvIGcZ2@uEe) z0RmY91hNDOWC;++5+INzKp^XFfES?XAAqU>vF9%I>wH%U00000NkvXXu0mjfTcDg{ literal 0 HcmV?d00001 diff --git a/chapter_preface/about_the_book/index.html b/chapter_preface/about_the_book/index.html index 322a470a4..e48651395 100644 --- a/chapter_preface/about_the_book/index.html +++ b/chapter_preface/about_the_book/index.html @@ -3554,7 +3554,7 @@

  • 数据结构:基本数据类型和数据结构的分类方法。数组、链表、栈、队列、哈希表、树、堆、图等数据结构的定义、优缺点、常用操作、常见类型、典型应用、实现方法等。
  • 算法:搜索、排序、分治、回溯、动态规划、贪心等算法的定义、优缺点、效率、应用场景、解题步骤和示例问题等。
  • -

    本书主要内容

    +

    本书主要内容

    图 0-1   本书主要内容

    0.1.3   致谢

    diff --git a/chapter_sorting/counting_sort/index.html b/chapter_sorting/counting_sort/index.html index f794e0eb2..d5f6514b7 100644 --- a/chapter_sorting/counting_sort/index.html +++ b/chapter_sorting/counting_sort/index.html @@ -3822,7 +3822,7 @@ } // 2. 统计各数字的出现次数 // counter[num] 代表 num 的出现次数 - int *counter = calloc(m, sizeof(int)); + int *counter = calloc(m + 1, sizeof(int)); for (int i = 0; i < size; i++) { counter[nums[i]]++; } diff --git a/chapter_tree/binary_search_tree/index.html b/chapter_tree/binary_search_tree/index.html index 0763c2d79..bdf88205d 100644 --- a/chapter_tree/binary_search_tree/index.html +++ b/chapter_tree/binary_search_tree/index.html @@ -4932,20 +4932,22 @@ } else { pre->right = child; } - } else { - /* 子节点数量 = 2 */ - // 获取中序遍历中 cur 的下一个节点 - TreeNode *tmp = cur->right; - while (tmp->left != NULL) { - tmp = tmp->left; - } - int tmpVal = tmp->val; - // 递归删除节点 tmp - removeItem(bst, tmp->val); - // 用 tmp 覆盖 cur - cur->val = tmpVal; - } -} + // 释放内存 + free(cur); + } else { + /* 子节点数量 = 2 */ + // 获取中序遍历中 cur 的下一个节点 + TreeNode *tmp = cur->right; + while (tmp->left != NULL) { + tmp = tmp->left; + } + int tmpVal = tmp->val; + // 递归删除节点 tmp + removeItem(bst, tmp->val); + // 用 tmp 覆盖 cur + cur->val = tmpVal; + } +}
    diff --git a/en/assets/covers/chapter_introduction.jpg b/en/assets/covers/chapter_introduction.jpg index 0c39cd5967c25d60cb52444ce1a60b6ebe52fbdd..47e448f33fa875a644bab9d1eece8488096300ab 100644 GIT binary patch delta 67335 zcmV)eK&HQl$_Sp!2(V59AT}{IFgZ6cG(j;rGchqmML|J1GDI~(IYc%?G%!U(HIr@v z93VC^H843hFf&0hIWsXaMMXhDIWj~wLODb>Lo_f&L^YGD0%IgOWn(ilV=y=^G-fq0 zEi^eXWi4SeGBYhQVq!HmG&wRhGG$@2F#|jS0kV^B1V91;1Cy`>G6s`G;)Aopv*`px zxdHvNF1~{f0g1D+%okOE{xoNRKjsnJ!neS%tK+9uOD+EZiujTRg{X4Am9Wg^S0=*r z9VOc4s@Wt7W50>29mYc{ndJk*IA=<;mNpeO$3^a3>0C+5ngKSk7kv2ko@tL?TP+T%Dn#oR^ER90DGo?JYa*t9k`!~t4pcw z&d;Y1rrV9rg?WYIebtk)he!@{ISLQ3Yo@;=OQr2rBrJUGnfxie)V`8wTx4t%el=aW z5ya9y2)Xz2tL%3!h~wCAXK~Re26%+|$;{AuUGUrjJCF{{YG;znxfr5$wHsDGI36#=^XhOp&79 zto$P&p5vW*nbb;D>KZdq&$hhJe^&BR?`u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j=3k|rqXcrd`wnH2mYtYuGt&}{=0WVJ2?-Xt7RvP%6)%|OnIb0Tu0?+mB>{m18Vz16YaHu6 zf`e_<3Suvb`{=%&+?;S6Z9#(mpS0DnzBy98!ivjpRf2hMVND`!V*}J@?b0u5PaS^R zGwa5K3L9AZbN>MQB?kKENp>6`Wc z04Sd9X;^(tBSnAm;d){}`7iSQTlQYIz6J*SUBdaIVeFx_Ofy0~m8TEzoy@HC{g69DtJ|+^*u%Ozfynx9JBV-#VRUl4y{L5n)vtB z&@nD>0;#CgpE|7*99Yy4EuJTZb#-77b8B#@s~g+0s{t1S==@m6R8-VaG1jiGuB>B# zHQ4j6$Av{>6LZYhUAdZyk)2}}3pQf@`k&7nTi;OrrOtM!9;a;&k-lZM$_L4_V@n)F(>$qD%z^PDrFu5jsE`teg6QNm;6Sk-9vsq z{h2?-KwI&u%fgD|;B7`fkpBSo-``6wsg8^G&`xyTp8#q+de2n< z0L{PI{3@q^t#x1g)BT^qk~Lc1kM^6@;ywQWIn}@OPxgNbsq39z{{S@KXYioErTaMa z==E-O+x0ssYRiZFK>2u%p0m|k{{YxxeU;zyJzY(|bm03bA)Xb+_s2RukM^6@{^8Ts z`oA61{hz|BddE~b?qBTw6t4=cA5Vb3uMo5EH(QH;8RciTSE_o_fo)YoT}MD`;$PR7 z=BV{$`Hfb(ww?yp#J8y@%xX2i%zgD0)O0qdYHnxWU31LTS5`4MJnHC*$n0DxP&BE{ zuga-iSjZuTgbOvsmL+uY!l_+dSj>SHc7T~mn|nxL+%WM5DOfP6eJov5&zwJ%45 z&Frjyw?T6ZV!HJeBG~z*L-#^5a1oZ-wnxAsMY|f^j1}E-E}7 zwOaf#R8Yl!w9ZioaAk$M@PTN&b AF8}}l diff --git a/en/sitemap.xml b/en/sitemap.xml index b8c7fd5be..859983cb3 100644 --- a/en/sitemap.xml +++ b/en/sitemap.xml @@ -2,137 +2,137 @@ https://www.hello-algo.com/en/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_array_and_linkedlist/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_array_and_linkedlist/array/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_array_and_linkedlist/linked_list/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_array_and_linkedlist/list/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_array_and_linkedlist/ram_and_cache/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_array_and_linkedlist/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_computational_complexity/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_computational_complexity/iteration_and_recursion/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_computational_complexity/performance_evaluation/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_computational_complexity/space_complexity/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_computational_complexity/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_computational_complexity/time_complexity/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_data_structure/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_data_structure/basic_data_types/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_data_structure/character_encoding/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_data_structure/classification_of_data_structure/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_data_structure/number_encoding/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_data_structure/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_introduction/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_introduction/algorithms_are_everywhere/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_introduction/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_introduction/what_is_dsa/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_preface/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_preface/about_the_book/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_preface/suggestions/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/en/chapter_preface/summary/ - 2024-01-02 + 2024-01-03 daily \ No newline at end of file diff --git a/en/sitemap.xml.gz b/en/sitemap.xml.gz index 601f6491be66c5688d49c3d13951089afe466920..a7291112334bfa46048b467287f53d52bb46cdf2 100644 GIT binary patch literal 451 zcmV;!0X+U6iwFo7FO_8i|8r?{Wo=<_E_iKh0Ns|&a-1*>$M1QH9qx-s+C$r6$*oV& zo;_M4z!QHEOAgt$uYql6bL^$FsxR1ogyttKTWX)*y*s>NA{)c0daRr3fWgGxhVfMW z{PF$xrF!lj+MFCAABu6HQ#CQq-;`RGr6$YhVWv8!QIVO-g49)1P5rg%9u8%!4))nL zS{F^XdZDYE37v~aaAT}Z^a_J&)oOG52@w0(cTdgJ=VSADY(5o}t9D~%CI}-A317P& zth==8M%h`^ADF+#D$Zucq#-4^Xb8P_HoRc(EU`%DO%zGKPqo-TFBUw3-y{R&yo-#0 zviFegKJCkL&J0}cW^mie;k#wI+@&t0P2M&np~+j}5gX5pX^6=~FsShjT;6QNhC?%y zK>mX~lYYM0dP)1x1A`_`*>FxMjP?v<%`Wm~MiPc!NA{)cGdaj%5fWgGxhVfke z`2Owqxq9iI+MFCAABu6Hb2Tx~UzJ*xr6$YhVWv8!QIVO-g49h^P5q_no(^TK4))nL zS{F^XdZC+}37v~aaAT}Z^a_J&)oOG92@w0(ccDW9Un^Q5lX?JF3f-vHc@MqV9 zb=OwiDLae$1M~M-#o5f5G^7Mq4WZZ0hF9#JB^JrNi6Y7OsTTX^#eygBn`EGzcaafL z_8!v1r+rz@nSsmQ3~pOFe77u@yVQlW$=ik`G-V8_o%Z(O!V8*+st2NW$=ooWQIve)sLt0w^S82W$4i5C_@m z6tcg_-3%cYrwyE9Uzi0{+YhX(L9#q~DvjydGhn(d6Fz>He~3b2mMjynwxoN4N9Uds t4y6&3f(e(HS@VSY6632BYRcn?w5A5hLH\u52a8\u753b\u56fe\u89e3\u3001\u4e00\u952e\u8fd0\u884c\u7684\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u6559\u7a0b

    \u5f00\u59cb\u9605\u8bfb \u4e0b\u8f7d\u4ee3\u7801 \u4e0b\u8f7d PDF

    \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

    \u52a8\u753b\u56fe\u89e3

    \u5185\u5bb9\u6e05\u6670\u6613\u61c2\u5b66\u4e60\u66f2\u7ebf\u5e73\u6ed1

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

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

    \u4e00\u952e\u8fd0\u884c

    \u5341\u4f59\u79cd\u7f16\u7a0b\u8bed\u8a00\u4ee3\u7801\u53ef\u76f4\u63a5\u8fd0\u884c

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

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

    \u4e92\u52a9\u5b66\u4e60

    \u6b22\u8fce\u8ba8\u8bba\u4e0e\u63d0\u95ee\u8bfb\u8005\u95f4\u643a\u624b\u5171\u8fdb

    \"\u8ffd\u98ce\u8d76\u6708\u83ab\u505c\u7559\"

    \u201c\u5e73\u829c\u5c3d\u5904\u662f\u6625\u5c71\u201d

    \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

    \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 30 \u4e07\u672c\u3002

    \u8d21\u732e

    \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 codingonion\u3001Gonglja\u3001gvenusleo\u3001hpstory\u3001justin\u2010tse\u3001krahets\u3001night-cruise\u3001nuomi1 \u548c Reanon \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

    codingonionRust, Zig GongljaC, C++ gvenusleoDart hpstoryC# justin-tseJS, TS krahetsJava, Python night-cruiseRust nuomi1Swift ReanonGo, C"},{"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 VS Code \u4f5c\u4e3a\u672c\u5730\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002\u8bbf\u95ee VS Code \u5b98\u7f51\uff0c\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u76f8\u5e94\u7248\u672c\u7684 VS Code \u8fdb\u884c\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002

    \u56fe 16-1 \u00a0 \u4ece\u5b98\u7f51\u4e0b\u8f7d VS Code

    VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 javascript \uff0c\u5b89\u88c5 JavaScript (ES6) code snippets \u3002
    3. \uff08\u53ef\u9009\uff09\u5728 VS Code \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 VS Code \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 VS Code \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\u8bfb\u8005\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 \\(O\\) \u8bb0\u53f7 big-\\(O\\) notation \u4f18\u5148\u961f\u5217 priority queue \u6e10\u8fd1\u4e0a\u754c asymptotic upper bound \u5806\u5316 heapify \u539f\u7801 sign-magnitude \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\u6982\u5ff5\u548c\u5b58\u50a8\u65b9\u5f0f\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\n    random_index = random.randint(0, len(nums) - 1)\n    # \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    random_num = nums[random_index]\n    return 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\n    int randomIndex = rand() % size;\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return 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\n    int randomIndex = ThreadLocalRandom.current().nextInt(0, nums.length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return randomNum;\n}\n
    array.cs
    /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint RandomAccess(int[] nums) {\n    Random random = new();\n    // \u5728\u533a\u95f4 [0, nums.Length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\n    int randomIndex = random.Next(nums.Length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return 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\n    randomIndex := rand.Intn(len(nums))\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    randomNum = nums[randomIndex]\n    return\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\n    let randomIndex = nums.indices.randomElement()!\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    let randomNum = nums[randomIndex]\n    return 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\n    const random_index = Math.floor(Math.random() * nums.length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    const random_num = nums[random_index];\n    return 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\n    const random_index = Math.floor(Math.random() * nums.length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    const random_num = nums[random_index];\n    return 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\n  int randomIndex = Random().nextInt(nums.length);\n  // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n  int randomNum = nums[randomIndex];\n  return 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\n    let random_index = rand::thread_rng().gen_range(0..nums.len());\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    let random_num = nums[random_index];\n    random_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\n    int randomIndex = rand() % size;\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return 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\n    var randomIndex = std.crypto.random.intRangeLessThan(usize, 0, nums.len);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    var randomNum = nums[randomIndex];\n    return 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\n    for i in range(len(nums) - 1, index, -1):\n        nums[i] = nums[i - 1]\n    # \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = size - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = nums.length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = nums.Length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for i := len(nums) - 1; i > index; i-- {\n        nums[i] = nums[i-1]\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for i in nums.indices.dropFirst(index).reversed() {\n        nums[i] = nums[i - 1]\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (let i = nums.length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (let i = nums.length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n  for (var i = nums.length - 1; i > index; i--) {\n    nums[i] = nums[i - 1];\n  }\n  // \u5c06 _num \u8d4b\u7ed9 index \u5904\u5143\u7d20\n  nums[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\n    for i in (index + 1..nums.len()).rev() {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = size - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    var i = nums.len - 1;\n    while (i > index) : (i -= 1) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for i in range(index, len(nums) - 1):\n        nums[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\n    for (int i = index; i < size - 1; i++) {\n        nums[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\n    for (int i = index; i < nums.length - 1; i++) {\n        nums[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\n    for (int i = index; i < nums.Length - 1; i++) {\n        nums[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\n    for i := index; i < len(nums)-1; i++ {\n        nums[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\n    for i in nums.indices.dropFirst(index).dropLast() {\n        nums[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\n    for (let i = index; i < nums.length - 1; i++) {\n        nums[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\n    for (let i = index; i < nums.length - 1; i++) {\n        nums[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\n  for (var i = index; i < nums.length - 1; i++) {\n    nums[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\n    for i in index..nums.len() - 1 {\n        nums[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\n    for (int i = index; i < size - 1; i++) {\n        nums[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\n    var i = index;\n    while (i < nums.len - 1) : (i += 1) {\n        nums[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\"\"\"\n    count = 0\n    # \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i in range(len(nums)):\n        count += nums[i]\n    # \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for num in nums:\n        count += num\n    # \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\n    for i, num in enumerate(nums):\n        count += nums[i]\n        count += num\n
    array.cpp
    /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        count += nums[i];\n    }\n}\n
    array.java
    /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int[] nums) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < nums.length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (int num : nums) {\n        count += num;\n    }\n}\n
    array.cs
    /* \u904d\u5386\u6570\u7ec4 */\nvoid Traverse(int[] nums) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < nums.Length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    foreach (int num in nums) {\n        count += num;\n    }\n}\n
    array.go
    /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums []int) {\n    count := 0\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i := 0; i < len(nums); i++ {\n        count += nums[i]\n    }\n    count = 0\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for _, num := range nums {\n        count += num\n    }\n    // \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\n    for i, num := range nums {\n        count += nums[i]\n        count += num\n    }\n}\n
    array.swift
    /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums: [Int]) {\n    var count = 0\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i in nums.indices {\n        count += nums[i]\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for num in nums {\n        count += num\n    }\n}\n
    array.js
    /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums) {\n    let count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (let i = 0; i < nums.length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (const num of nums) {\n        count += num;\n    }\n}\n
    array.ts
    /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums: number[]): void {\n    let count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (let i = 0; i < nums.length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (const num of nums) {\n        count += num;\n    }\n}\n
    array.dart
    /* \u904d\u5386\u6570\u7ec4\u5143\u7d20 */\nvoid traverse(List<int> nums) {\n  int count = 0;\n  // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n  for (var i = 0; i < nums.length; i++) {\n    count += nums[i];\n  }\n  // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n  for (int _num in nums) {\n    count += _num;\n  }\n  // \u901a\u8fc7 forEach \u65b9\u6cd5\u904d\u5386\u6570\u7ec4\n  nums.forEach((_num) {\n    count += _num;\n  });\n}\n
    array.rs
    /* \u904d\u5386\u6570\u7ec4 */\nfn traverse(nums: &[i32]) {\n    let mut _count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i in 0..nums.len() {\n        _count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for num in nums {\n        _count += num;\n    }\n}\n
    array.c
    /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        count += nums[i];\n    }\n}\n
    array.zig
    // \u904d\u5386\u6570\u7ec4\nfn traverse(nums: []i32) void {\n    var count: i32 = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    var i: i32 = 0;\n    while (i < nums.len) : (i += 1) {\n        count += nums[i];\n    }\n    count = 0;\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (nums) |num| {\n        count += 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\"\"\"\n    for i in range(len(nums)):\n        if nums[i] == target:\n            return i\n    return -1\n
    array.cpp
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\n    for (int i = 0; i < size; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.java
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int[] nums, int target) {\n    for (int i = 0; i < nums.length; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.cs
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint Find(int[] nums, int target) {\n    for (int i = 0; i < nums.Length; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.go
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums []int, target int) (index int) {\n    index = -1\n    for i := 0; i < len(nums); i++ {\n        if nums[i] == target {\n            index = i\n            break\n        }\n    }\n    return\n}\n
    array.swift
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums: [Int], target: Int) -> Int {\n    for i in nums.indices {\n        if nums[i] == target {\n            return i\n        }\n    }\n    return -1\n}\n
    array.js
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums, target) {\n    for (let i = 0; i < nums.length; i++) {\n        if (nums[i] === target) return i;\n    }\n    return -1;\n}\n
    array.ts
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums: number[], target: number): number {\n    for (let i = 0; i < nums.length; i++) {\n        if (nums[i] === target) {\n            return i;\n        }\n    }\n    return -1;\n}\n
    array.dart
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(List<int> nums, int target) {\n  for (var i = 0; i < nums.length; i++) {\n    if (nums[i] == target) return i;\n  }\n  return -1;\n}\n
    array.rs
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfn find(nums: &[i32], target: i32) -> Option<usize> {\n    for i in 0..nums.len() {\n        if nums[i] == target {\n            return Some(i);\n        }\n    }\n    None\n}\n
    array.c
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\n    for (int i = 0; i < size; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.zig
    // \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\nfn find(nums: []i32, target: i32) i32 {\n    for (nums, 0..) |num, i| {\n        if (num == target) return @intCast(i);\n    }\n    return -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\n    res = [0] * (len(nums) + enlarge)\n    # \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for i in range(len(nums)):\n        res[i] = nums[i]\n    # \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    int *res = new int[size + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        res[i] = nums[i];\n    }\n    // \u91ca\u653e\u5185\u5b58\n    delete[] nums;\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    int[] res = new int[nums.length + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < nums.length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    int[] res = new int[nums.Length + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < nums.Length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    res := make([]int, len(nums)+enlarge)\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for i, num := range nums {\n        res[i] = num\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    var 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\n    for i in nums.indices {\n        res[i] = nums[i]\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    const 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\n    for (let i = 0; i < nums.length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    const 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\n    for (let i = 0; i < nums.length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n  List<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\n  for (var i = 0; i < nums.length; i++) {\n    res[i] = nums[i];\n  }\n  // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n  return 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\n    let mut res: Vec<i32> = vec![0; nums.len() + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\n    for i in 0..nums.len() {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    res\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\n    int *res = (int *)malloc(sizeof(int) * (size + enlarge));\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        res[i] = nums[i];\n    }\n    // \u521d\u59cb\u5316\u6269\u5c55\u540e\u7684\u7a7a\u95f4\n    for (int i = size; i < size + enlarge; i++) {\n        res[i] = 0;\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    var 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\n    std.mem.copy(i32, res, nums);\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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 null\u3001nullptr \u548c None \u3002
    • \u5728 C\u3001C++\u3001Go \u548c Rust \u7b49\u652f\u6301\u6307\u9488\u7684\u8bed\u8a00\u4e2d\uff0c\u4e0a\u8ff0\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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val               # \u8282\u70b9\u503c\n        self.next: ListNode | None = None # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n
    /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct ListNode {\n    int val;         // \u8282\u70b9\u503c\n    ListNode *next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n    ListNode(int x) : val(x), next(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    int val;        // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    ListNode(int x) { val = x; }  // \u6784\u9020\u51fd\u6570\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode(int x) {  //\u6784\u9020\u51fd\u6570\n    int val = x;         // \u8282\u70b9\u503c\n    ListNode? next;      // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype ListNode struct {\n    Val  int       // \u8282\u70b9\u503c\n    Next *ListNode // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n}\n\n// NewListNode \u6784\u9020\u51fd\u6570\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u94fe\u8868\nfunc NewListNode(val int) *ListNode {\n    return &ListNode{\n        Val:  val,\n        Next: nil,\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    var val: Int // \u8282\u70b9\u503c\n    var next: ListNode? // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n\n    init(x: Int) { // \u6784\u9020\u51fd\u6570\n        val = x\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    constructor(val, next) {\n        this.val = (val === undefined ? 0 : val);       // \u8282\u70b9\u503c\n        this.next = (next === undefined ? null : next); // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    val: number;\n    next: ListNode | null;\n    constructor(val?: number, next?: ListNode | null) {\n        this.val = val === undefined ? 0 : val;        // \u8282\u70b9\u503c\n        this.next = next === undefined ? null : next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n  int val; // \u8282\u70b9\u503c\n  ListNode? next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n  ListNode(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 {\n    val: i32, // \u8282\u70b9\u503c\n    next: 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 {\n    int val;               // \u8282\u70b9\u503c\n    struct ListNode *next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\n    ListNode *node;\n    node = (ListNode *) malloc(sizeof(ListNode));\n    node->val = val;\n    node->next = NULL;\n    return node;\n}\n
    // \u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        val: T = 0, // \u8282\u70b9\u503c\n        next: ?*Self = null, // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n\n        // \u6784\u9020\u51fd\u6570\n        pub fn init(self: *Self, x: i32) void {\n            self.val = x;\n            self.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\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\"\"\"\n    n1 = n0.next\n    P.next = n1\n    n0.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) {\n    ListNode *n1 = n0->next;\n    P->next = n1;\n    n0->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) {\n    ListNode n1 = n0.next;\n    P.next = n1;\n    n0.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) {\n    ListNode? n1 = n0.next;\n    P.next = n1;\n    n0.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) {\n    n1 := n0.Next\n    P.Next = n1\n    n0.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) {\n    let n1 = n0.next\n    P.next = n1\n    n0.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) {\n    const n1 = n0.next;\n    P.next = n1;\n    n0.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 {\n    const n1 = n0.next;\n    P.next = n1;\n    n0.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) {\n  ListNode? n1 = n0.next;\n  P.next = n1;\n  n0.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>>>) {\n    let n1 =  n0.borrow_mut().next.take();\n    P.borrow_mut().next = n1;\n    n0.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) {\n    ListNode *n1 = n0->next;\n    P->next = n1;\n    n0->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 {\n    var n1 = n0.?.next;\n    P.?.next = n1;\n    n0.?.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\"\"\"\n    if not n0.next:\n        return\n    # n0 -> P -> n1\n    P = n0.next\n    n1 = P.next\n    n0.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) {\n    if (n0->next == nullptr)\n        return;\n    // n0 -> P -> n1\n    ListNode *P = n0->next;\n    ListNode *n1 = P->next;\n    n0->next = n1;\n    // \u91ca\u653e\u5185\u5b58\n    delete 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) {\n    if (n0.next == null)\n        return;\n    // n0 -> P -> n1\n    ListNode P = n0.next;\n    ListNode n1 = P.next;\n    n0.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) {\n    if (n0.next == null)\n        return;\n    // n0 -> P -> n1\n    ListNode P = n0.next;\n    ListNode? n1 = P.next;\n    n0.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) {\n    if n0.Next == nil {\n        return\n    }\n    // n0 -> P -> n1\n    P := n0.Next\n    n1 := P.Next\n    n0.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) {\n    if n0.next == nil {\n        return\n    }\n    // n0 -> P -> n1\n    let P = n0.next\n    let n1 = P?.next\n    n0.next = n1\n    P?.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) {\n    if (!n0.next) return;\n    // n0 -> P -> n1\n    const P = n0.next;\n    const n1 = P.next;\n    n0.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 {\n    if (!n0.next) {\n        return;\n    }\n    // n0 -> P -> n1\n    const P = n0.next;\n    const n1 = P.next;\n    n0.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) {\n  if (n0.next == null) return;\n  // n0 -> P -> n1\n  ListNode P = n0.next!;\n  ListNode? n1 = P.next;\n  n0.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>>>) {\n    if n0.borrow().next.is_none() {return};\n    // n0 -> P -> n1\n    let P = n0.borrow_mut().next.take();\n    if let Some(node) = P {\n        let n1 = node.borrow_mut().next.take();\n        n0.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) {\n    if (!n0->next)\n        return;\n    // n0 -> P -> n1\n    ListNode *P = n0->next;\n    ListNode *n1 = P->next;\n    n0->next = n1;\n    // \u91ca\u653e\u5185\u5b58\n    free(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 {\n    if (n0.?.next == null) return;\n    // n0 -> P -> n1\n    var P = n0.?.next;\n    var n1 = P.?.next;\n    n0.?.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\"\"\"\n    for _ in range(index):\n        if not head:\n            return None\n        head = head.next\n    return head\n
    linked_list.cpp
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == nullptr)\n            return nullptr;\n        head = head->next;\n    }\n    return head;\n}\n
    linked_list.java
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode access(ListNode head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == null)\n            return null;\n        head = head.next;\n    }\n    return head;\n}\n
    linked_list.cs
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? Access(ListNode? head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == null)\n            return null;\n        head = head.next;\n    }\n    return 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 {\n    for i := 0; i < index; i++ {\n        if head == nil {\n            return nil\n        }\n        head = head.Next\n    }\n    return 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? {\n    var head: ListNode? = head\n    for _ in 0 ..< index {\n        if head == nil {\n            return nil\n        }\n        head = head?.next\n    }\n    return head\n}\n
    linked_list.js
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunction access(head, index) {\n    for (let i = 0; i < index; i++) {\n        if (!head) {\n            return null;\n        }\n        head = head.next;\n    }\n    return 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 {\n    for (let i = 0; i < index; i++) {\n        if (!head) {\n            return null;\n        }\n        head = head.next;\n    }\n    return head;\n}\n
    linked_list.dart
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? access(ListNode? head, int index) {\n  for (var i = 0; i < index; i++) {\n    if (head == null) return null;\n    head = head.next;\n  }\n  return 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>>> {\n    if index <= 0 {return head};\n    if let Some(node) = &head.borrow_mut().next {\n        return access(node.clone(), index - 1);\n    }\n    return head;\n}\n
    linked_list.c
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == NULL)\n            return NULL;\n        head = head->next;\n    }\n    return 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) {\n    var head = node;\n    var i: i32 = 0;\n    while (i < index) : (i += 1) {\n        head = head.?.next;\n        if (head == null) return null;\n    }\n    return 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\"\"\"\n    index = 0\n    while head:\n        if head.val == target:\n            return index\n        head = head.next\n        index += 1\n    return -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) {\n    int index = 0;\n    while (head != nullptr) {\n        if (head->val == target)\n            return index;\n        head = head->next;\n        index++;\n    }\n    return -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) {\n    int index = 0;\n    while (head != null) {\n        if (head.val == target)\n            return index;\n        head = head.next;\n        index++;\n    }\n    return -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) {\n    int index = 0;\n    while (head != null) {\n        if (head.val == target)\n            return index;\n        head = head.next;\n        index++;\n    }\n    return -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 {\n    index := 0\n    for head != nil {\n        if head.Val == target {\n            return index\n        }\n        head = head.Next\n        index++\n    }\n    return -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 {\n    var head: ListNode? = head\n    var index = 0\n    while head != nil {\n        if head?.val == target {\n            return index\n        }\n        head = head?.next\n        index += 1\n    }\n    return -1\n}\n
    linked_list.js
    /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunction find(head, target) {\n    let index = 0;\n    while (head !== null) {\n        if (head.val === target) {\n            return index;\n        }\n        head = head.next;\n        index += 1;\n    }\n    return -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 {\n    let index = 0;\n    while (head !== null) {\n        if (head.val === target) {\n            return index;\n        }\n        head = head.next;\n        index += 1;\n    }\n    return -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) {\n  int index = 0;\n  while (head != null) {\n    if (head.val == target) {\n      return index;\n    }\n    head = head.next;\n    index++;\n  }\n  return -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 {\n    if head.borrow().val == target {return index};\n    if let Some(node) = &head.borrow_mut().next {\n        return find(node.clone(), target, index + 1);\n    }\n    return -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) {\n    int index = 0;\n    while (head) {\n        if (head->val == target)\n            return index;\n        head = head->next;\n        index++;\n    }\n    return -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 {\n    var head = node;\n    var index: i32 = 0;\n    while (head != null) {\n        if (head.?.val == target) return index;\n        head = head.?.next;\n        index += 1;\n    }\n    return -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 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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val                # \u8282\u70b9\u503c\n        self.next: ListNode | None = None  # \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n        self.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 {\n    int val;         // \u8282\u70b9\u503c\n    ListNode *next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    ListNode *prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n    ListNode(int x) : val(x), next(nullptr), prev(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    int val;        // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    ListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n    ListNode(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\n    int val = x;    // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    ListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype DoublyListNode struct {\n    Val  int             // \u8282\u70b9\u503c\n    Next *DoublyListNode // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    Prev *DoublyListNode // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n\n// NewDoublyListNode \u521d\u59cb\u5316\nfunc NewDoublyListNode(val int) *DoublyListNode {\n    return &DoublyListNode{\n        Val:  val,\n        Next: nil,\n        Prev: nil,\n    }\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    var val: Int // \u8282\u70b9\u503c\n    var next: ListNode? // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    var prev: ListNode? // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n\n    init(x: Int) { // \u6784\u9020\u51fd\u6570\n        val = x\n    }\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    constructor(val, next, prev) {\n        this.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\n        this.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n        this.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 {\n    val: number;\n    next: ListNode | null;\n    prev: ListNode | null;\n    constructor(val?: number, next?: ListNode | null, prev?: ListNode | null) {\n        this.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\n        this.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n        this.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 {\n    int val;        // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    ListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n    ListNode(this.val, [this.next, this.prev]);  // \u6784\u9020\u51fd\u6570\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\u578b */\n#[derive(Debug)]\nstruct ListNode {\n    val: i32, // \u8282\u70b9\u503c\n    next: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    prev: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nimpl ListNode {\n    fn new(val: i32) -> Self {\n        ListNode {\n            val,\n            next: None,\n            prev: None,\n        }\n    }\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct ListNode {\n    int val;               // \u8282\u70b9\u503c\n    struct ListNode *next; // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    struct ListNode *prev; // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\n    ListNode *node;\n    node = (ListNode *) malloc(sizeof(ListNode));\n    node->val = val;\n    node->next = NULL;\n    node->prev = NULL;\n    return node;\n}\n
    // \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        val: T = 0, // \u8282\u70b9\u503c\n        next: ?*Self = null, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n        prev: ?*Self = null, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n\n        // \u6784\u9020\u51fd\u6570\n        pub fn init(self: *Self, x: i32) void {\n            self.val = x;\n            self.next = null;\n            self.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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\n# \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n\n# \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\nnums.insert(3, 6)  # \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\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\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\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.add(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.Add(1);\nnums.Add(3);\nnums.Add(2);\nnums.Add(5);\nnums.Add(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.Insert(3, 6);\n\n/* \u5220\u9664\u5143\u7d20 */\nnums.RemoveAt(3);\n
    list_test.go
    /* \u6e05\u7a7a\u5217\u8868 */\nnums = nil\n\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\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\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(6, at: 3) // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
    list.ts
    /* \u6e05\u7a7a\u5217\u8868 */\nnums.length = 0;\n\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
    list.dart
    /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\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\n// \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\ntry nums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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)):\n    count += nums[i]\n\n# \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\nfor num in nums:\n    count += num\n
    list.cpp
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (int num : nums) {\n    count += num;\n}\n
    list.java
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\n    count += nums.get(i);\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\nfor (int num : nums) {\n    count += num;\n}\n
    list.cs
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.Count; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nforeach (int num in nums) {\n    count += num;\n}\n
    list_test.go
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\ncount := 0\nfor i := 0; i < len(nums); i++ {\n    count += nums[i]\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor _, num := range nums {\n    count += num\n}\n
    list.swift
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nvar count = 0\nfor i in nums.indices {\n    count += nums[i]\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor num in nums {\n    count += num\n}\n
    list.js
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\n    count += num;\n}\n
    list.ts
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\n    count += num;\n}\n
    list.dart
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (var i = 0; i < nums.length; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (var num in nums) {\n    count += 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\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) {\n    count += nums[i];\n}\n\n// \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\ncount = 0;\nfor (nums.items) |num| {\n    count += 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 */  \nnums.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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._capacity: int = 10  # \u5217\u8868\u5bb9\u91cf\n        self._arr: list[int] = [0] * self._capacity  # \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n        self._size: int = 0  # \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n        self._extend_ratio: int = 2  # \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\"\"\"\n        return self._size\n\n    def capacity(self) -> int:\n        \"\"\"\u83b7\u53d6\u5217\u8868\u5bb9\u91cf\"\"\"\n        return self._capacity\n\n    def get(self, index: int) -> int:\n        \"\"\"\u8bbf\u95ee\u5143\u7d20\"\"\"\n        # \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        return self._arr[index]\n\n    def set(self, num: int, index: int):\n        \"\"\"\u66f4\u65b0\u5143\u7d20\"\"\"\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        self._arr[index] = num\n\n    def 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\n        if self.size() == self.capacity():\n            self.extend_capacity()\n        self._arr[self._size] = num\n        self._size += 1\n\n    def insert(self, num: int, index: int):\n        \"\"\"\u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\"\"\"\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        # \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if self._size == self.capacity():\n            self.extend_capacity()\n        # \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for j in range(self._size - 1, index - 1, -1):\n            self._arr[j + 1] = self._arr[j]\n        self._arr[index] = num\n        # \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self._size += 1\n\n    def remove(self, index: int) -> int:\n        \"\"\"\u5220\u9664\u5143\u7d20\"\"\"\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        num = self._arr[index]\n        # \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for j in range(index, self._size - 1):\n            self._arr[j] = self._arr[j + 1]\n        # \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self._size -= 1\n        # \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num\n\n    def 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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        self._arr = self._arr + [0] * self.capacity() * (self._extend_ratio - 1)\n        # \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        self._capacity = len(self._arr)\n\n    def to_array(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u6709\u6548\u957f\u5ea6\u7684\u5217\u8868\"\"\"\n        return self._arr[: self._size]\n
    my_list.cpp
    /* \u5217\u8868\u7c7b */\nclass MyList {\n  private:\n    int *arr;             // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    int arrCapacity = 10; // \u5217\u8868\u5bb9\u91cf\n    int arrSize = 0;      // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    int extendRatio = 2;   // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    MyList() {\n        arr = new int[arrCapacity];\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~MyList() {\n        delete[] arr;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    int size() {\n        return arrSize;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    int capacity() {\n        return arrCapacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    int get(int index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        return arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    void set(int index, int num) {\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    void add(int num) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size() == capacity())\n            extendCapacity();\n        arr[size()] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    void insert(int index, int num) {\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size() == capacity())\n            extendCapacity();\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (int 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        arrSize++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    int remove(int index) {\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        int num = arr[index];\n        // \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (int j = index; j < size() - 1; j++) {\n            arr[j] = arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    void extendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\n        int newCapacity = capacity() * extendRatio;\n        int *tmp = arr;\n        arr = new int[newCapacity];\n        // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        for (int i = 0; i < size(); i++) {\n            arr[i] = tmp[i];\n        }\n        // \u91ca\u653e\u5185\u5b58\n        delete[] tmp;\n        arrCapacity = newCapacity;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Vector \u7528\u4e8e\u6253\u5370 */\n    vector<int> toVector() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        vector<int> vec(size());\n        for (int i = 0; i < size(); i++) {\n            vec[i] = arr[i];\n        }\n        return vec;\n    }\n};\n
    my_list.java
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private int[] arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private int capacity = 10; // \u5217\u8868\u5bb9\u91cf\n    private int size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private int extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public MyList() {\n        arr = new int[capacity];\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\n    public int size() {\n        return size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    public int capacity() {\n        return capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    public int get(int index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        return arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    public void set(int index, int num) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    public void add(int num) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size == capacity())\n            extendCapacity();\n        arr[size] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        size++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    public void insert(int index, int num) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size == capacity())\n            extendCapacity();\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (int 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\n    /* \u5220\u9664\u5143\u7d20 */\n    public int remove(int index) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        int num = arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (int 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\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    public 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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        arr = Arrays.copyOf(arr, capacity() * extendRatio);\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        capacity = arr.length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    public int[] toArray() {\n        int size = size();\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] arr = new int[size];\n        for (int i = 0; i < size; i++) {\n            arr[i] = get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.cs
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private int[] arr;           // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private int arrCapacity = 10;    // \u5217\u8868\u5bb9\u91cf\n    private int arrSize = 0;         // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private readonly int extendRatio = 2;  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public MyList() {\n        arr = new int[arrCapacity];\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    public int Size() {\n        return arrSize;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    public int Capacity() {\n        return arrCapacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    public int Get(int index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        return arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    public void Set(int index, int num) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    public void Add(int num) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (arrSize == arrCapacity)\n            ExtendCapacity();\n        arr[arrSize] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    public void Insert(int index, int num) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (arrSize == arrCapacity)\n            ExtendCapacity();\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (int j = arrSize - 1; j >= index; j--) {\n            arr[j + 1] = arr[j];\n        }\n        arr[index] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    public int Remove(int index) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        int num = arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (int j = index; j < arrSize - 1; j++) {\n            arr[j] = arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    public void ExtendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a arrCapacity * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        Array.Resize(ref arr, arrCapacity * extendRatio);\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        arrCapacity = arr.Length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    public int[] ToArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] arr = new int[arrSize];\n        for (int i = 0; i < arrSize; i++) {\n            arr[i] = Get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.go
    /* \u5217\u8868\u7c7b */\ntype myList struct {\n    arrCapacity int\n    arr         []int\n    arrSize     int\n    extendRatio int\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nfunc newMyList() *myList {\n    return &myList{\n        arrCapacity: 10,              // \u5217\u8868\u5bb9\u91cf\n        arr:         make([]int, 10), // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n        arrSize:     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    }\n}\n\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\nfunc (l *myList) size() int {\n    return l.arrSize\n}\n\n/*  \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nfunc (l *myList) capacity() int {\n    return l.arrCapacity\n}\n\n/* \u8bbf\u95ee\u5143\u7d20 */\nfunc (l *myList) get(index int) int {\n    // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    return l.arr[index]\n}\n\n/* \u66f4\u65b0\u5143\u7d20 */\nfunc (l *myList) set(num, index int) {\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    l.arr[index] = num\n}\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\n    if l.arrSize == l.arrCapacity {\n        l.extendCapacity()\n    }\n    l.arr[l.arrSize] = num\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    l.arrSize++\n}\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nfunc (l *myList) insert(num, index int) {\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n    if l.arrSize == l.arrCapacity {\n        l.extendCapacity()\n    }\n    // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    for j := l.arrSize - 1; j >= index; j-- {\n        l.arr[j+1] = l.arr[j]\n    }\n    l.arr[index] = num\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    l.arrSize++\n}\n\n/* \u5220\u9664\u5143\u7d20 */\nfunc (l *myList) remove(index int) int {\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    num := l.arr[index]\n    // \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n    for j := index; j < l.arrSize-1; j++ {\n        l.arr[j] = l.arr[j+1]\n    }\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    l.arrSize--\n    // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n    return num\n}\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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    l.arr = append(l.arr, make([]int, l.arrCapacity*(l.extendRatio-1))...)\n    // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n    l.arrCapacity = len(l.arr)\n}\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\n    return l.arr[:l.arrSize]\n}\n
    my_list.swift
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private var arr: [Int] // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private var _capacity = 10 // \u5217\u8868\u5bb9\u91cf\n    private var _size = 0 // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private let extendRatio = 2 // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init() {\n        arr = Array(repeating: 0, count: _capacity)\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    func size() -> Int {\n        _size\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    func capacity() -> Int {\n        _capacity\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    func get(index: Int) -> Int {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u9519\u8bef\uff0c\u4e0b\u540c\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        return arr[index]\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    func set(index: Int, num: Int) {\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        arr[index] = num\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    func add(num: Int) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if _size == _capacity {\n            extendCapacity()\n        }\n        arr[_size] = num\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        _size += 1\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    func insert(index: Int, num: Int) {\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if _size == _capacity {\n            extendCapacity()\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for j in sequence(first: _size - 1, next: { $0 >= index + 1 ? $0 - 1 : nil }) {\n            arr[j + 1] = arr[j]\n        }\n        arr[index] = num\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        _size += 1\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    @discardableResult\n    func remove(index: Int) -> Int {\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        let num = arr[index]\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for j in index ..< (_size - 1) {\n            arr[j] = arr[j + 1]\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        _size -= 1\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    func extendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        arr = arr + Array(repeating: 0, count: _capacity * (extendRatio - 1))\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        _capacity = arr.count\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    func toArray() -> [Int] {\n        var arr = Array(repeating: 0, count: _size)\n        for i in 0 ..< _size {\n            arr[i] = get(index: i)\n        }\n        return 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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#arr = new Array(this.#capacity);\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    size() {\n        return this.#size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    capacity() {\n        return this.#capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    get(index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        return this.#arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    set(index, num) {\n        if (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        this.#arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    add(num) {\n        // \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\n        if (this.#size === this.#capacity) {\n            this.extendCapacity();\n        }\n        // \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\n        this.#arr[this.#size] = num;\n        this.#size++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    insert(index, num) {\n        if (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\n        if (this.#size === this.#capacity) {\n            this.extendCapacity();\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (let j = this.#size - 1; j >= index; j--) {\n            this.#arr[j + 1] = this.#arr[j];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this.#arr[index] = num;\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    remove(index) {\n        if (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        let num = this.#arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (let j = index; j < this.#size - 1; j++) {\n            this.#arr[j] = this.#arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this.#size--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    extendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        this.#arr = this.#arr.concat(\n            new Array(this.capacity() * (this.#extendRatio - 1))\n        );\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        this.#capacity = this.#arr.length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    toArray() {\n        let size = this.size();\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(size);\n        for (let i = 0; i < size; i++) {\n            arr[i] = this.get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.ts
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private arr: Array<number>; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private _capacity: number = 10; // \u5217\u8868\u5bb9\u91cf\n    private _size: number = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private extendRatio: number = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.arr = new Array(this._capacity);\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    public size(): number {\n        return this._size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    public capacity(): number {\n        return this._capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    public get(index: number): number {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        return this.arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    public set(index: number, num: number): void {\n        if (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        this.arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    public add(num: number): void {\n        // \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\n        if (this._size === this._capacity) this.extendCapacity();\n        // \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\n        this.arr[this._size] = num;\n        this._size++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    public insert(index: number, num: number): void {\n        if (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\n        if (this._size === this._capacity) {\n            this.extendCapacity();\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (let j = this._size - 1; j >= index; j--) {\n            this.arr[j + 1] = this.arr[j];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this.arr[index] = num;\n        this._size++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    public remove(index: number): number {\n        if (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        let num = this.arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (let j = index; j < this._size - 1; j++) {\n            this.arr[j] = this.arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this._size--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    public extendCapacity(): void {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        this.arr = this.arr.concat(\n            new Array(this.capacity() * (this.extendRatio - 1))\n        );\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        this._capacity = this.arr.length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    public toArray(): number[] {\n        let size = this.size();\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(size);\n        for (let i = 0; i < size; i++) {\n            arr[i] = this.get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.dart
    /* \u5217\u8868\u7c7b */\nclass MyList {\n  late List<int> _arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n  int _capacity = 10; // \u5217\u8868\u5bb9\u91cf\n  int _size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n  int _extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  MyList() {\n    _arr = List.filled(_capacity, 0);\n  }\n\n  /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n  int size() => _size;\n\n  /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n  int capacity() => _capacity;\n\n  /* \u8bbf\u95ee\u5143\u7d20 */\n  int get(int index) {\n    if (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n    return _arr[index];\n  }\n\n  /* \u66f4\u65b0\u5143\u7d20 */\n  void set(int index, int _num) {\n    if (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n    _arr[index] = _num;\n  }\n\n  /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n  void add(int _num) {\n    // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n    if (_size == _capacity) extendCapacity();\n    _arr[_size] = _num;\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    _size++;\n  }\n\n  /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n  void insert(int index, int _num) {\n    if (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\n    if (_size == _capacity) extendCapacity();\n    // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    for (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\n  /* \u5220\u9664\u5143\u7d20 */\n  int remove(int index) {\n    if (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n    int _num = _arr[index];\n    // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n    for (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\u7684\u5143\u7d20\n    return _num;\n  }\n\n  /* \u5217\u8868\u6269\u5bb9 */\n  void extendCapacity() {\n    // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 _extendRatio \u500d\u7684\u65b0\u6570\u7ec4\n    final _newNums = List.filled(_capacity * _extendRatio, 0);\n    // \u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    List.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\n  /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n  List<int> toArray() {\n    List<int> arr = [];\n    for (var i = 0; i < _size; i++) {\n      arr.add(get(i));\n    }\n    return arr;\n  }\n}\n
    my_list.rs
    /* \u5217\u8868\u7c7b */\n#[allow(dead_code)]\nstruct MyList {\n    arr: Vec<i32>,       // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    capacity: usize,      // \u5217\u8868\u5bb9\u91cf\n    size: usize,          // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    extend_ratio: usize,  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n}\n\n#[allow(unused,unused_comparisons)]\nimpl MyList {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(capacity: usize) -> Self {\n        let mut vec = Vec::new(); \n        vec.resize(capacity, 0);\n        Self {\n            arr: vec,\n            capacity,\n            size: 0,\n            extend_ratio: 2,\n        }\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    pub fn size(&self) -> usize {\n        return self.size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    pub fn capacity(&self) -> usize {\n        return self.capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    pub fn get(&self, index: usize) -> i32 {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n        return self.arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    pub fn set(&mut self, index: usize, num: i32) {\n        if index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n        self.arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    pub fn add(&mut self, num: i32) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if self.size == self.capacity() {\n            self.extend_capacity();\n        }\n        self.arr[self.size] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self.size += 1;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    pub fn insert(&mut self, index: usize, num: i32) {\n        if 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\n        if self.size == self.capacity() {\n            self.extend_capacity();\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for j in (index..self.size).rev() {\n            self.arr[j + 1] = self.arr[j];\n        }\n        self.arr[index] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self.size += 1;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    pub fn remove(&mut self, index: usize) -> i32 {\n        if index >= self.size() {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n        let num = self.arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for j in (index..self.size - 1) {\n            self.arr[j] = self.arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self.size -= 1;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    pub 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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        let new_capacity = self.capacity * self.extend_ratio;\n        self.arr.resize(new_capacity, 0);\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        self.capacity = new_capacity;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    pub fn to_array(&mut self) -> Vec<i32> {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        let mut arr = Vec::new();\n        for i in 0..self.size {\n            arr.push(self.get(i));\n        }\n        arr\n    }\n}\n
    my_list.c
    /* \u5217\u8868\u7c7b */\ntypedef struct {\n    int *arr;        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    int capacity;    // \u5217\u8868\u5bb9\u91cf\n    int size;        // \u5217\u8868\u5927\u5c0f\n    int extendRatio; // \u5217\u8868\u6bcf\u6b21\u6269\u5bb9\u7684\u500d\u6570\n} MyList;\n\n/* \u6784\u9020\u51fd\u6570 */\nMyList *newMyList() {\n    MyList *nums = malloc(sizeof(MyList));\n    nums->capacity = 10;\n    nums->arr = malloc(sizeof(int) * nums->capacity);\n    nums->size = 0;\n    nums->extendRatio = 2;\n    return nums;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delMyList(MyList *nums) {\n    free(nums->arr);\n    free(nums);\n}\n\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6 */\nint size(MyList *nums) {\n    return nums->size;\n}\n\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity(MyList *nums) {\n    return nums->capacity;\n}\n\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(MyList *nums, int index) {\n    assert(index >= 0 && index < nums->size);\n    return nums->arr[index];\n}\n\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(MyList *nums, int index, int num) {\n    assert(index >= 0 && index < nums->size);\n    nums->arr[index] = num;\n}\n\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(MyList *nums, int num) {\n    if (size(nums) == capacity(nums)) {\n        extendCapacity(nums); // \u6269\u5bb9\n    }\n    nums->arr[size(nums)] = num;\n    nums->size++;\n}\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(MyList *nums, int index, int num) {\n    assert(index >= 0 && index < size(nums));\n    // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n    if (size(nums) == capacity(nums)) {\n        extendCapacity(nums); // \u6269\u5bb9\n    }\n    for (int i = size(nums); i > index; --i) {\n        nums->arr[i] = nums->arr[i - 1];\n    }\n    nums->arr[index] = num;\n    nums->size++;\n}\n\n/* \u5220\u9664\u5143\u7d20 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nint removeItem(MyList *nums, int index) {\n    assert(index >= 0 && index < size(nums));\n    int num = nums->arr[index];\n    for (int i = index; i < size(nums) - 1; i++) {\n        nums->arr[i] = nums->arr[i + 1];\n    }\n    nums->size--;\n    return num;\n}\n\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity(MyList *nums) {\n    // \u5148\u5206\u914d\u7a7a\u95f4\n    int newCapacity = capacity(nums) * nums->extendRatio;\n    int *extend = (int *)malloc(sizeof(int) * newCapacity);\n    int *temp = nums->arr;\n\n    // \u62f7\u8d1d\u65e7\u6570\u636e\u5230\u65b0\u6570\u636e\n    for (int i = 0; i < size(nums); i++)\n        extend[i] = nums->arr[i];\n\n    // \u91ca\u653e\u65e7\u6570\u636e\n    free(temp);\n\n    // \u66f4\u65b0\u65b0\u6570\u636e\n    nums->arr = extend;\n    nums->capacity = newCapacity;\n}\n\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Array \u7528\u4e8e\u6253\u5370 */\nint *toArray(MyList *nums) {\n    return nums->arr;\n}\n
    my_list.zig
    // \u5217\u8868\u7c7b\nfn MyList(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        arr: []T = undefined,                        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n        arrCapacity: usize = 10,                     // \u5217\u8868\u5bb9\u91cf\n        numSize: usize = 0,                           // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n        extendRatio: usize = 2,                       // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined, // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u5217\u8868\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.arr = try self.mem_allocator.alloc(T, self.arrCapacity);\n            @memset(self.arr, @as(T, 0));\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n        pub fn size(self: *Self) usize {\n            return self.numSize;\n        }\n\n        // \u83b7\u53d6\u5217\u8868\u5bb9\u91cf\n        pub fn capacity(self: *Self) usize {\n            return self.arrCapacity;\n        }\n\n        // \u8bbf\u95ee\u5143\u7d20\n        pub fn get(self: *Self, index: usize) T {\n            // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n            if (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n            return self.arr[index];\n        }  \n\n        // \u66f4\u65b0\u5143\u7d20\n        pub fn set(self: *Self, index: usize, num: T) void {\n            // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n            if (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n            self.arr[index] = num;\n        }  \n\n        // \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\n        pub fn add(self: *Self, num: T) !void {\n            // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n            if (self.size() == self.capacity()) try self.extendCapacity();\n            self.arr[self.size()] = num;\n            // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n            self.numSize += 1;\n        }  \n\n        // \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\n        pub fn insert(self: *Self, index: usize, num: T) !void {\n            if (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\n            if (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\n            var j = self.size() - 1;\n            while (j >= index) : (j -= 1) {\n                self.arr[j + 1] = self.arr[j];\n            }\n            self.arr[index] = num;\n            // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n            self.numSize += 1;\n        }\n\n        // \u5220\u9664\u5143\u7d20\n        pub fn remove(self: *Self, index: usize) T {\n            if (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n            var num = self.arr[index];\n            // \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n            var j = index;\n            while (j < self.size() - 1) : (j += 1) {\n                self.arr[j] = self.arr[j + 1];\n            }\n            // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n            self.numSize -= 1;\n            // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n            return num;\n        }\n\n        // \u5217\u8868\u6269\u5bb9\n        pub fn extendCapacity(self: *Self) !void {\n            // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n            var newCapacity = self.capacity() * self.extendRatio;\n            var 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\n            std.mem.copy(T, extend, self.arr);\n            self.arr = extend;\n            // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n            self.arrCapacity = newCapacity;\n        }\n\n        // \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n            var arr = try self.mem_allocator.alloc(T, self.size());\n           @memset(arr, @as(T, 0));\n            for (arr, 0..) |*num, i| {\n                num.* = self.get(i);\n            }\n            return 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\u4e24\u79cd\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\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\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\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\u4e09\u8005\u5171\u540c\u534f\u4f5c\uff0c\u786e\u4fdd\u8ba1\u7b97\u673a\u7cfb\u7edf\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 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\u5404\u81ea\u5177\u6709\u4f18\u52bf\u548c\u5c40\u9650\u6027\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\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\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\u53ea\u80fd\u5b58\u50a8\u4e00\u5c0f\u90e8\u5206\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\uff0c\u56e0\u6b64\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\u7684\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\u8fd1\u671f\u4e5f\u4f1a\u88ab\u8bbf\u95ee\u3002\u56e0\u6b64\uff0c\u7f13\u5b58\u5728\u52a0\u8f7d\u67d0\u4e00\u6570\u636e\u65f6\uff0c\u4e5f\u4f1a\u52a0\u8f7d\u5176\u9644\u8fd1\u7684\u6570\u636e\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\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\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\u9644\u8fd1\u7684\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\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\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\u5b83\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\u53ef\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\u5c40\u90e8\u6027\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\u57fa\u672c\u4e00\u81f4\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 \u5b57\u8282 \u548c 8 \u5b57\u8282 \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\u201c\u5143\u7d20\u957f\u5ea6\u201d\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 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\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\"\"\"\n    if root is None:\n        return\n    if root.val == 7:\n        # \u8bb0\u5f55\u89e3\n        res.append(root)\n    pre_order(root.left)\n    pre_order(root.right)\n
    preorder_traversal_i_compact.cpp
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode *root) {\n    if (root == nullptr) {\n        return;\n    }\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push_back(root);\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n}\n
    preorder_traversal_i_compact.java
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode root) {\n    if (root == null) {\n        return;\n    }\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.add(root);\n    }\n    preOrder(root.left);\n    preOrder(root.right);\n}\n
    preorder_traversal_i_compact.cs
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid PreOrder(TreeNode? root) {\n    if (root == null) {\n        return;\n    }\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.Add(root);\n    }\n    PreOrder(root.left);\n    PreOrder(root.right);\n}\n
    preorder_traversal_i_compact.go
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrderI(root *TreeNode, res *[]*TreeNode) {\n    if root == nil {\n        return\n    }\n    if (root.Val).(int) == 7 {\n        // \u8bb0\u5f55\u89e3\n        *res = append(*res, root)\n    }\n    preOrderI(root.Left, res)\n    preOrderI(root.Right, res)\n}\n
    preorder_traversal_i_compact.swift
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    if root.val == 7 {\n        // \u8bb0\u5f55\u89e3\n        res.append(root)\n    }\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n}\n
    preorder_traversal_i_compact.js
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunction preOrder(root, res) {\n    if (root === null) {\n        return;\n    }\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push(root);\n    }\n    preOrder(root.left, res);\n    preOrder(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 {\n    if (root === null) {\n        return;\n    }\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push(root);\n    }\n    preOrder(root.left, res);\n    preOrder(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) {\n  if (root == null) {\n    return;\n  }\n  if (root.val == 7) {\n    // \u8bb0\u5f55\u89e3\n    res.add(root);\n  }\n  preOrder(root.left, res);\n  preOrder(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>>>) {\n    if root.is_none() {\n        return;\n    }\n    if let Some(node) = root {\n        if node.borrow().val == 7 {\n            // \u8bb0\u5f55\u89e3\n            res.push(node.clone());\n        }\n        pre_order(res, node.borrow().left.clone());\n        pre_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) {\n    if (root == NULL) {\n        return;\n    }\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res[resSize++] = root;\n    }\n    preOrder(root->left);\n    preOrder(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\"\"\"\n    if root is None:\n        return\n    # \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7:\n        # \u8bb0\u5f55\u89e3\n        res.append(list(path))\n    pre_order(root.left)\n    pre_order(root.right)\n    # \u56de\u9000\n    path.pop()\n
    preorder_traversal_ii_compact.cpp
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\n    if (root == nullptr) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push_back(root);\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push_back(path);\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    path.pop_back();\n}\n
    preorder_traversal_ii_compact.java
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode root) {\n    if (root == null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.add(new ArrayList<>(path));\n    }\n    preOrder(root.left);\n    preOrder(root.right);\n    // \u56de\u9000\n    path.remove(path.size() - 1);\n}\n
    preorder_traversal_ii_compact.cs
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid PreOrder(TreeNode? root) {\n    if (root == null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.Add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.Add(new List<TreeNode>(path));\n    }\n    PreOrder(root.left);\n    PreOrder(root.right);\n    // \u56de\u9000\n    path.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) {\n    if root == nil {\n        return\n    }\n    // \u5c1d\u8bd5\n    *path = append(*path, root)\n    if root.Val.(int) == 7 {\n        // \u8bb0\u5f55\u89e3\n        *res = append(*res, append([]*TreeNode{}, *path...))\n    }\n    preOrderII(root.Left, res, path)\n    preOrderII(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?) {\n    guard let root = root else {\n        return\n    }\n    // \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7 {\n        // \u8bb0\u5f55\u89e3\n        res.append(path)\n    }\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n    // \u56de\u9000\n    path.removeLast()\n}\n
    preorder_traversal_ii_compact.js
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(root, path, res) {\n    if (root === null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_ii_compact.ts
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(\n    root: TreeNode | null,\n    path: TreeNode[],\n    res: TreeNode[][]\n): void {\n    if (root === null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_ii_compact.dart
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(\n  TreeNode? root,\n  List<TreeNode> path,\n  List<List<TreeNode>> res,\n) {\n  if (root == null) {\n    return;\n  }\n\n  // \u5c1d\u8bd5\n  path.add(root);\n  if (root.val == 7) {\n    // \u8bb0\u5f55\u89e3\n    res.add(List.from(path));\n  }\n  preOrder(root.left, path, res);\n  preOrder(root.right, path, res);\n  // \u56de\u9000\n  path.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>>>) {\n    if root.is_none() {\n        return;\n    }\n    if let Some(node) = root {\n        // \u5c1d\u8bd5\n        path.push(node.clone());\n        if node.borrow().val == 7 {\n            // \u8bb0\u5f55\u89e3\n            res.push(path.clone());\n        }\n        pre_order(res, path, node.borrow().left.clone());\n        pre_order(res, path, node.borrow().right.clone());\n        // \u56de\u9000\n        path.remove(path.len() -  1);\n    }\n}\n
    preorder_traversal_ii_compact.c
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\n    if (root == NULL) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path[pathSize++] = root;\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        for (int i = 0; i < pathSize; ++i) {\n            res[resSize][i] = path[i];\n        }\n        resSize++;\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    pathSize--;\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\n    if root is None or root.val == 3:\n        return\n    # \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7:\n        # \u8bb0\u5f55\u89e3\n        res.append(list(path))\n    pre_order(root.left)\n    pre_order(root.right)\n    # \u56de\u9000\n    path.pop()\n
    preorder_traversal_iii_compact.cpp
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode *root) {\n    // \u526a\u679d\n    if (root == nullptr || root->val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push_back(root);\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push_back(path);\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    path.pop_back();\n}\n
    preorder_traversal_iii_compact.java
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode root) {\n    // \u526a\u679d\n    if (root == null || root.val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.add(new ArrayList<>(path));\n    }\n    preOrder(root.left);\n    preOrder(root.right);\n    // \u56de\u9000\n    path.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\n    if (root == null || root.val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.Add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.Add(new List<TreeNode>(path));\n    }\n    PreOrder(root.left);\n    PreOrder(root.right);\n    // \u56de\u9000\n    path.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\n    if root == nil || root.Val == 3 {\n        return\n    }\n    // \u5c1d\u8bd5\n    *path = append(*path, root)\n    if root.Val.(int) == 7 {\n        // \u8bb0\u5f55\u89e3\n        *res = append(*res, *path)\n    }\n    preOrderIII(root.Left, res, path)\n    preOrderIII(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\n    guard let root = root, root.val != 3 else {\n        return\n    }\n    // \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7 {\n        // \u8bb0\u5f55\u89e3\n        res.append(path)\n    }\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n    // \u56de\u9000\n    path.removeLast()\n}\n
    preorder_traversal_iii_compact.js
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(root, path, res) {\n    // \u526a\u679d\n    if (root === null || root.val === 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_iii_compact.ts
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(\n    root: TreeNode | null,\n    path: TreeNode[],\n    res: TreeNode[][]\n): void {\n    // \u526a\u679d\n    if (root === null || root.val === 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_iii_compact.dart
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(\n  TreeNode? root,\n  List<TreeNode> path,\n  List<List<TreeNode>> res,\n) {\n  if (root == null || root.val == 3) {\n    return;\n  }\n\n  // \u5c1d\u8bd5\n  path.add(root);\n  if (root.val == 7) {\n    // \u8bb0\u5f55\u89e3\n    res.add(List.from(path));\n  }\n  preOrder(root.left, path, res);\n  preOrder(root.right, path, res);\n  // \u56de\u9000\n  path.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\n    if root.is_none() || root.as_ref().unwrap().borrow().val == 3 {\n        return;\n    }\n    if let Some(node) = root {\n        // \u5c1d\u8bd5\n        path.push(node.clone());\n        if node.borrow().val == 7 {\n            // \u8bb0\u5f55\u89e3\n            res.push(path.clone());\n        }\n        pre_order(res, path, node.borrow().left.clone());\n        pre_order(res, path, node.borrow().right.clone());\n        // \u56de\u9000\n        path.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\n    if (root == NULL || root->val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path[pathSize++] = root;\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        for (int i = 0; i < pathSize; i++) {\n            res[resSize][i] = path[i];\n        }\n        resSize++;\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    pathSize--;\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\n    if is_solution(state):\n        # \u8bb0\u5f55\u89e3\n        record_solution(state, res)\n        # \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices:\n        # \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice):\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice)\n            backtrack(state, choices, res)\n            # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undo_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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (Choice choice : choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (Choice choice : choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (IsSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        RecordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    foreach (Choice choice in choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (IsValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            MakeChoice(state, choice);\n            Backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            UndoChoice(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\n    if isSolution(state) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res)\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for _, choice := range choices {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state, choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice)\n            backtrack(state, choices, res)\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if isSolution(state: state) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state: state, res: &res)\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state: state, choice: choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state: &state, choice: choice)\n            backtrack(state: &state, choices: choices, res: &res)\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (let choice of choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (let choice of choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n  if (isSolution(state)) {\n    // \u8bb0\u5f55\u89e3\n    recordSolution(state, res);\n    // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (Choice choice in choices) {\n    // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n    if (isValid(state, choice)) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      makeChoice(state, choice);\n      backtrack(state, choices, res);\n      // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n      undoChoice(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\n    if is_solution(state) {\n        // \u8bb0\u5f55\u89e3\n        record_solution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undo_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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res, numRes);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < numChoices; i++) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, &choices[i])) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, &choices[i]);\n            backtrack(state, choices, numChoices, res, numRes);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\"\"\"\n    return state and state[-1].val == 7\n\ndef record_solution(state: list[TreeNode], res: list[list[TreeNode]]):\n    \"\"\"\u8bb0\u5f55\u89e3\"\"\"\n    res.append(list(state))\n\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\"\"\"\n    return choice is not None and choice.val != 3\n\ndef make_choice(state: list[TreeNode], choice: TreeNode):\n    \"\"\"\u66f4\u65b0\u72b6\u6001\"\"\"\n    state.append(choice)\n\ndef undo_choice(state: list[TreeNode], choice: TreeNode):\n    \"\"\"\u6062\u590d\u72b6\u6001\"\"\"\n    state.pop()\n\ndef backtrack(\n    state: 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\n    if is_solution(state):\n        # \u8bb0\u5f55\u89e3\n        record_solution(state, res)\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices:\n        # \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice):\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice)\n            # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state, [choice.left, choice.right], res)\n            # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undo_choice(state, choice)\n
    preorder_traversal_iii_template.cpp
    /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(vector<TreeNode *> &state) {\n    return !state.empty() && state.back()->val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(vector<TreeNode *> &state, vector<vector<TreeNode *>> &res) {\n    res.push_back(state);\n}\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) {\n    return choice != nullptr && choice->val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(vector<TreeNode *> &state, TreeNode *choice) {\n    state.push_back(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(vector<TreeNode *> &state, TreeNode *choice) {\n    state.pop_back();\n}\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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (TreeNode *choice : choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            vector<TreeNode *> nextChoices{choice->left, choice->right};\n            backtrack(state, nextChoices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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) {\n    return !state.isEmpty() && state.get(state.size() - 1).val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\n    res.add(new ArrayList<>(state));\n}\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) {\n    return choice != null && choice.val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode choice) {\n    state.add(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode choice) {\n    state.remove(state.size() - 1);\n}\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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (TreeNode choice : choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            undoChoice(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) {\n    return state.Count != 0 && state[^1].val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid RecordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\n    res.Add(new List<TreeNode>(state));\n}\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) {\n    return choice != null && choice.val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid MakeChoice(List<TreeNode> state, TreeNode choice) {\n    state.Add(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid UndoChoice(List<TreeNode> state, TreeNode choice) {\n    state.RemoveAt(state.Count - 1);\n}\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\n    if (IsSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        RecordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    foreach (TreeNode choice in choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (IsValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            MakeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            Backtrack(state, [choice.left!, choice.right!], res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            UndoChoice(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 {\n    return len(*state) != 0 && (*state)[len(*state)-1].Val == 7\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state *[]*TreeNode, res *[][]*TreeNode) {\n    *res = append(*res, *state)\n}\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 {\n    return choice != nil && choice.Val != 3\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state *[]*TreeNode, choice *TreeNode) {\n    *state = append(*state, choice)\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state *[]*TreeNode, choice *TreeNode) {\n    *state = (*state)[:len(*state)-1]\n}\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\n    if isSolution(state) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for _, choice := range *choices {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state, choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            temp := make([]*TreeNode, 0)\n            temp = append(temp, choice.Left, choice.Right)\n            backtrackIII(state, &temp, res)\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state: [TreeNode], res: inout [[TreeNode]]) {\n    res.append(state)\n}\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 {\n    choice != nil && choice!.val != 3\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state: inout [TreeNode], choice: TreeNode) {\n    state.append(choice)\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state: inout [TreeNode], choice: TreeNode) {\n    state.removeLast()\n}\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\n    if isSolution(state: state) {\n        recordSolution(state: state, res: &res)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state: state, choice: choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state: &state, choice: choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            undoChoice(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) {\n    return state && state[state.length - 1]?.val === 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state, res) {\n    res.push([...state]);\n}\n\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunction isValid(state, choice) {\n    return choice !== null && choice.val !== 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state, choice) {\n    state.push(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state) {\n    state.pop();\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(state, choices, res) {\n    // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state, [choice.left, choice.right], res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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 {\n    return state && state[state.length - 1]?.val === 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state: TreeNode[], res: TreeNode[][]): void {\n    res.push([...state]);\n}\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 {\n    return choice !== null && choice.val !== 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state: TreeNode[], choice: TreeNode): void {\n    state.push(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state: TreeNode[]): void {\n    state.pop();\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(\n    state: TreeNode[],\n    choices: TreeNode[],\n    res: TreeNode[][]\n): void {\n    // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state, [choice.left, choice.right], res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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) {\n  return state.isNotEmpty && state.last.val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\n  res.add(List.from(state));\n}\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) {\n  return choice != null && choice.val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode? choice) {\n  state.add(choice!);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode? choice) {\n  state.removeLast();\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(\n  List<TreeNode> state,\n  List<TreeNode?> choices,\n  List<List<TreeNode>> res,\n) {\n  // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n  if (isSolution(state)) {\n    // \u8bb0\u5f55\u89e3\n    recordSolution(state, res);\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (TreeNode? choice in choices) {\n    // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n    if (isValid(state, choice)) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      makeChoice(state, choice);\n      // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n      backtrack(state, [choice!.left, choice.right], res);\n      // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n      undoChoice(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 {\n    return !state.is_empty() && state.get(state.len() - 1).unwrap().borrow().val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfn record_solution(state: &mut Vec<Rc<RefCell<TreeNode>>>, res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>) {\n    res.push(state.clone());\n}\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 {\n    return choice.borrow().val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfn make_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, choice: Rc<RefCell<TreeNode>>) {\n    state.push(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfn undo_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, _: Rc<RefCell<TreeNode>>) {\n    state.remove(state.len() - 1);\n}\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\n    if is_solution(state) {\n        // \u8bb0\u5f55\u89e3\n        record_solution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice.clone()) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice.clone());\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            undo_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) {\n    return pathSize > 0 && path[pathSize - 1]->val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(void) {\n    for (int i = 0; i < pathSize; i++) {\n        res[resSize][i] = path[i];\n    }\n    resSize++;\n}\n\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(TreeNode *choice) {\n    return choice != NULL && choice->val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(TreeNode *choice) {\n    path[pathSize++] = choice;\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(void) {\n    pathSize--;\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(TreeNode *choices[2]) {\n    // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n    if (isSolution()) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution();\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < 2; i++) {\n        TreeNode *choice = choices[i];\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            TreeNode *nextChoices[2] = {choice->left, choice->right};\n            backtrack(nextChoices);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice();\n        }\n    }\n}\n
    preorder_traversal_iii_template.zig
    [class]{}-[func]{isSolution}\n\n[class]{}-[func]{recordSolution}\n\n[class]{}-[func]{isValid}\n\n[class]{}-[func]{makeChoice}\n\n[class]{}-[func]{undoChoice}\n\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\u6761\u5bf9\u89d2\u7ebf\u4e0a\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(\n    row: int,\n    n: int,\n    state: list[list[str]],\n    res: list[list[list[str]]],\n    cols: list[bool],\n    diags1: list[bool],\n    diags2: list[bool],\n):\n    \"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e\"\"\"\n    # \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if row == n:\n        res.append([list(row) for row in state])\n        return\n    # \u904d\u5386\u6240\u6709\u5217\n    for col in range(n):\n        # \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        diag1 = row - col + n - 1\n        diag2 = row + col\n        # \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if not cols[col] and not diags1[diag1] and not 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\n            # \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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\n\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\n    state = [[\"#\" for _ in range(n)] for _ in range(n)]\n    cols = [False] * n  # \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    diags1 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    diags2 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    res = []\n    backtrack(0, n, state, res, cols, diags1, diags2)\n\n    return 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,\n               vector<bool> &diags1, vector<bool> &diags2) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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;\n        }\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\n    vector<vector<string>> state(n, vector<string>(n, \"#\"));\n    vector<bool> cols(n, false);           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    vector<bool> diags1(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    vector<bool> diags2(2 * n - 1, false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    vector<vector<vector<string>>> res;\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n\n    return 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,\n        boolean[] cols, boolean[] diags1, boolean[] diags2) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        List<List<String>> copyState = new ArrayList<>();\n        for (List<String> sRow : state) {\n            copyState.add(new ArrayList<>(sRow));\n        }\n        res.add(copyState);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n            // \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n            state.get(row).set(col, \"Q\");\n            cols[col] = diags1[diag1] = diags2[diag2] = true;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(row + 1, n, state, res, cols, diags1, diags2);\n            // \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n            state.get(row).set(col, \"#\");\n            cols[col] = diags1[diag1] = diags2[diag2] = false;\n        }\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\n    List<List<String>> state = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n        List<String> row = new ArrayList<>();\n        for (int j = 0; j < n; j++) {\n            row.add(\"#\");\n        }\n        state.add(row);\n    }\n    boolean[] cols = new boolean[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    boolean[] diags1 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    boolean[] diags2 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    List<List<List<String>>> res = new ArrayList<>();\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n\n    return 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,\n        bool[] cols, bool[] diags1, bool[] diags2) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        List<List<string>> copyState = [];\n        foreach (List<string> sRow in state) {\n            copyState.Add(new List<string>(sRow));\n        }\n        res.Add(copyState);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            Backtrack(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;\n        }\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\n    List<List<string>> state = [];\n    for (int i = 0; i < n; i++) {\n        List<string> row = [];\n        for (int j = 0; j < n; j++) {\n            row.Add(\"#\");\n        }\n        state.Add(row);\n    }\n    bool[] cols = new bool[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    bool[] diags1 = new bool[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    bool[] diags2 = new bool[2 * n - 1]; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    List<List<List<string>>> res = [];\n\n    Backtrack(0, n, state, res, cols, diags1, diags2);\n\n    return 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\n    if row == n {\n        newState := make([][]string, len(*state))\n        for i, _ := range newState {\n            newState[i] = make([]string, len((*state)[0]))\n            copy(newState[i], (*state)[i])\n\n        }\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col := 0; col < n; col++ {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        diag1 := row - col + n - 1\n        diag2 := row + col\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !(*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\n            backtrack(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\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\n    if row == n {\n        newState := make([][]string, len(*state))\n        for i, _ := range newState {\n            newState[i] = make([]string, len((*state)[0]))\n            copy(newState[i], (*state)[i])\n\n        }\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col := 0; col < n; col++ {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        diag1 := row - col + n - 1\n        diag2 := row + col\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !(*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\n            backtrack(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\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\n    state := make([][]string, n)\n    for i := 0; i < n; i++ {\n        row := make([]string, n)\n        for i := 0; i < n; i++ {\n            row[i] = \"#\"\n        }\n        state[i] = row\n    }\n    // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    cols := make([]bool, n)\n    diags1 := make([]bool, 2*n-1)\n    diags2 := make([]bool, 2*n-1)\n    res := make([][][]string, 0)\n    backtrack(0, n, &state, &res, &cols, &diags1, &diags2)\n    return 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\n    if row == n {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col in 0 ..< n {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        let diag1 = row - col + n - 1\n        let diag2 = row + col\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !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] = true\n            diags1[diag1] = true\n            diags2[diag2] = true\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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\n            state[row][col] = \"#\"\n            cols[col] = false\n            diags1[diag1] = false\n            diags2[diag2] = false\n        }\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\n    var state = Array(repeating: Array(repeating: \"#\", count: n), count: n)\n    var cols = Array(repeating: false, count: n) // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    var diags1 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    var diags2 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    var res: [[[String]]] = []\n\n    backtrack(row: 0, n: n, state: &state, res: &res, cols: &cols, diags1: &diags1, diags2: &diags2)\n\n    return 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\n    if (row === n) {\n        res.push(state.map((row) => row.slice()));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (let col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        const diag1 = row - col + n - 1;\n        const diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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;\n        }\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\n    const state = Array.from({ length: n }, () => Array(n).fill('#'));\n    const cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    const diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const res = [];\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n    return res;\n}\n
    n_queens.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunction backtrack(\n    row: number,\n    n: number,\n    state: string[][],\n    res: string[][][],\n    cols: boolean[],\n    diags1: boolean[],\n    diags2: boolean[]\n): void {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row === n) {\n        res.push(state.map((row) => row.slice()));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (let col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        const diag1 = row - col + n - 1;\n        const diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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;\n        }\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\n    const state = Array.from({ length: n }, () => Array(n).fill('#'));\n    const cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    const diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const res: string[][][] = [];\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n    return res;\n}\n
    n_queens.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(\n  int row,\n  int n,\n  List<List<String>> state,\n  List<List<List<String>>> res,\n  List<bool> cols,\n  List<bool> diags1,\n  List<bool> diags2,\n) {\n  // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (row == n) {\n    List<List<String>> copyState = [];\n    for (List<String> sRow in state) {\n      copyState.add(List.from(sRow));\n    }\n    res.add(copyState);\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u5217\n  for (int col = 0; col < n; col++) {\n    // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n    int diag1 = row - col + n - 1;\n    int diag2 = row + col;\n    // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n    if (!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] = true;\n      diags1[diag1] = true;\n      diags2[diag2] = true;\n      // \u653e\u7f6e\u4e0b\u4e00\u884c\n      backtrack(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] = false;\n      diags1[diag1] = false;\n      diags2[diag2] = false;\n    }\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\n  List<List<String>> state = List.generate(n, (index) => List.filled(n, \"#\"));\n  List<bool> cols = List.filled(n, false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n  List<bool> diags1 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n  List<bool> diags2 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n  List<List<List<String>>> res = [];\n\n  backtrack(0, n, state, res, cols, diags1, diags2);\n\n  return 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>>>,\n    cols: &mut [bool], diags1: &mut [bool], diags2: &mut [bool]) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if row == n {\n        let mut copy_state: Vec<Vec<String>> = Vec::new();\n        for s_row in state.clone() {\n            copy_state.push(s_row);\n        }\n        res.push(copy_state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col in 0..n {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        let diag1 = row + n - 1 - col;\n        let diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !cols[col] && !diags1[diag1] && !diags2[diag2] {\n            // \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n            state.get_mut(row).unwrap()[col] = \"Q\".into();\n            (cols[col], diags1[diag1], diags2[diag2]) = (true, true, true);\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(row + 1, n, state, res, cols, diags1, diags2);\n            // \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n            state.get_mut(row).unwrap()[col] = \"#\".into();\n            (cols[col], diags1[diag1], diags2[diag2]) = (false, false, false);\n        }\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\n    let mut state: Vec<Vec<String>> = Vec::new();\n    for _ in 0..n {\n        let mut row: Vec<String> = Vec::new();\n        for _ in 0..n {\n            row.push(\"#\".into());\n        }\n        state.push(row);\n    }\n    let mut cols = vec![false; n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    let mut diags1 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    let mut diags2 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    let mut res: Vec<Vec<Vec<String>>> = Vec::new();\n\n    backtrack(0, n, &mut state, &mut res, &mut cols, &mut diags1, &mut diags2);\n\n    res\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],\n               bool diags1[2 * MAX_SIZE - 1], bool diags2[2 * MAX_SIZE - 1]) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        res[*resSize] = (char **)malloc(sizeof(char *) * n);\n        for (int i = 0; i < n; ++i) {\n            res[*resSize][i] = (char *)malloc(sizeof(char) * (n + 1));\n            strcpy(res[*resSize][i], state[i]);\n        }\n        (*resSize)++;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(row + 1, n, state, res, resSize, 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;\n        }\n    }\n}\n\n/* \u6c42\u89e3 N \u7687\u540e */\nchar ***nQueens(int n, int *returnSize) {\n    char 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\n    for (int i = 0; i < n; ++i) {\n        for (int j = 0; j < n; ++j) {\n            state[i][j] = '#';\n        }\n        state[i][n] = '\\0';\n    }\n    bool cols[MAX_SIZE] = {false};           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    bool diags1[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    bool diags2[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n\n    char ***res = (char ***)malloc(sizeof(char **) * MAX_SIZE);\n    *returnSize = 0;\n    backtrack(0, n, state, res, returnSize, cols, diags1, diags2);\n    return res;\n}\n
    n_queens.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if len(state) == len(choices):\n        res.append(list(state))\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i, choice in enumerate(choices):\n        # \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if not selected[i]:\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = True\n            state.append(choice)\n            # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop()\n\ndef permutations_i(nums: list[int]) -> list[list[int]]:\n    \"\"\"\u5168\u6392\u5217 I\"\"\"\n    res = []\n    backtrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\n    return 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\n    if (state.size() == choices.size()) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choices.size(); i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push_back(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop_back();\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nvector<vector<int>> permutationsI(vector<int> nums) {\n    vector<int> state;\n    vector<bool> selected(nums.size(), false);\n    vector<vector<int>> res;\n    backtrack(state, nums, selected, res);\n    return 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\n    if (state.size() == choices.length) {\n        res.add(new ArrayList<Integer>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choices.length; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.remove(state.size() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nList<List<Integer>> permutationsI(int[] nums) {\n    List<List<Integer>> res = new ArrayList<List<Integer>>();\n    backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\n    return 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\n    if (state.Count == choices.Length) {\n        res.Add(new List<int>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choices.Length; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.Add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            Backtrack(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.RemoveAt(state.Count - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nList<List<int>> PermutationsI(int[] nums) {\n    List<List<int>> res = [];\n    Backtrack([], nums, new bool[nums.Length], res);\n    return 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\n    if len(*state) == len(*choices) {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i := 0; i < len(*choices); i++ {\n        choice := (*choices)[i]\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if !(*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\n            backtrackI(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\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums []int) [][]int {\n    res := make([][]int, 0)\n    state := make([]int, 0)\n    selected := make([]bool, len(nums))\n    backtrackI(&state, &nums, &selected, &res)\n    return 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\n    if state.count == choices.count {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (i, choice) in choices.enumerated() {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if !selected[i] {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true\n            state.append(choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false\n            state.removeLast()\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums: [Int]) -> [[Int]] {\n    var state: [Int] = []\n    var selected = Array(repeating: false, count: nums.count)\n    var res: [[Int]] = []\n    backtrack(state: &state, choices: nums, selected: &selected, res: &res)\n    return 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\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    choices.forEach((choice, i) => {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums) {\n    const res = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_i.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunction backtrack(\n    state: number[],\n    choices: number[],\n    selected: boolean[],\n    res: number[][]\n): void {\n    // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    choices.forEach((choice, i) => {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums: number[]): number[][] {\n    const res: number[][] = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_i.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(\n  List<int> state,\n  List<int> choices,\n  List<bool> selected,\n  List<List<int>> res,\n) {\n  // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (state.length == choices.length) {\n    res.add(List.from(state));\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (int i = 0; i < choices.length; i++) {\n    int choice = choices[i];\n    // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n    if (!selected[i]) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      selected[i] = true;\n      state.add(choice);\n      // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n      backtrack(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.removeLast();\n    }\n  }\n}\n\n/* \u5168\u6392\u5217 I */\nList<List<int>> permutationsI(List<int> nums) {\n  List<List<int>> res = [];\n  backtrack([], nums, List.filled(nums.length, false), res);\n  return 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\n    if state.len() == choices.len() {\n        res.push(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i in 0..choices.len() {\n        let choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if !selected[i] {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state.clone(), 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.remove(state.len() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nfn permutations_i(nums: &mut [i32]) -> Vec<Vec<i32>> {\n    let mut res = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    backtrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\n    res\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\n    if (stateSize == choicesSize) {\n        res[*resSize] = (int *)malloc(choicesSize * sizeof(int));\n        for (int i = 0; i < choicesSize; i++) {\n            res[*resSize][i] = state[i];\n        }\n        (*resSize)++;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choicesSize; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state[stateSize] = choice;\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false;\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nint **permutationsI(int *nums, int numsSize, int *returnSize) {\n    int *state = (int *)malloc(numsSize * sizeof(int));\n    bool *selected = (bool *)malloc(numsSize * sizeof(bool));\n    for (int i = 0; i < numsSize; i++) {\n        selected[i] = false;\n    }\n    int **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n    *returnSize = 0;\n\n    backtrack(state, 0, nums, numsSize, selected, res, returnSize);\n\n    free(state);\n    free(selected);\n\n    return res;\n}\n
    permutations_i.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if len(state) == len(choices):\n        res.append(list(state))\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    duplicated = set[int]()\n    for 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\n        if not selected[i] and choice not in duplicated:\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice)  # \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = True\n            state.append(choice)\n            # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop()\n\ndef permutations_ii(nums: list[int]) -> list[list[int]]:\n    \"\"\"\u5168\u6392\u5217 II\"\"\"\n    res = []\n    backtrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\n    return 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\n    if (state.size() == choices.size()) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    unordered_set<int> duplicated;\n    for (int i = 0; i < choices.size(); i++) {\n        int 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\n        if (!selected[i] && duplicated.find(choice) == duplicated.end()) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.emplace(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push_back(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop_back();\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nvector<vector<int>> permutationsII(vector<int> nums) {\n    vector<int> state;\n    vector<bool> selected(nums.size(), false);\n    vector<vector<int>> res;\n    backtrack(state, nums, selected, res);\n    return 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\n    if (state.size() == choices.length) {\n        res.add(new ArrayList<Integer>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    Set<Integer> duplicated = new HashSet<Integer>();\n    for (int i = 0; i < choices.length; i++) {\n        int 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\n        if (!selected[i] && !duplicated.contains(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.remove(state.size() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nList<List<Integer>> permutationsII(int[] nums) {\n    List<List<Integer>> res = new ArrayList<List<Integer>>();\n    backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\n    return 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\n    if (state.Count == choices.Length) {\n        res.Add(new List<int>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    HashSet<int> duplicated = [];\n    for (int i = 0; i < choices.Length; i++) {\n        int 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\n        if (!selected[i] && !duplicated.Contains(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.Add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.Add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            Backtrack(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.RemoveAt(state.Count - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nList<List<int>> PermutationsII(int[] nums) {\n    List<List<int>> res = [];\n    Backtrack([], nums, new bool[nums.Length], res);\n    return 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\n    if len(*state) == len(*choices) {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    duplicated := make(map[int]struct{}, 0)\n    for i := 0; i < len(*choices); i++ {\n        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\n        if _, 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\n            duplicated[choice] = struct{}{}\n            (*selected)[i] = true\n            *state = append(*state, choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrackI(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\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums []int) [][]int {\n    res := make([][]int, 0)\n    state := make([]int, 0)\n    selected := make([]bool, len(nums))\n    backtrackII(&state, &nums, &selected, &res)\n    return 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\n    if state.count == choices.count {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    var duplicated: Set<Int> = []\n    for (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\n        if !selected[i], !duplicated.contains(choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.insert(choice) // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true\n            state.append(choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false\n            state.removeLast()\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums: [Int]) -> [[Int]] {\n    var state: [Int] = []\n    var selected = Array(repeating: false, count: nums.count)\n    var res: [[Int]] = []\n    backtrack(state: &state, choices: nums, selected: &selected, res: &res)\n    return 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\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    const duplicated = new Set();\n    choices.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\n        if (!selected[i] && !duplicated.has(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums) {\n    const res = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_ii.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunction backtrack(\n    state: number[],\n    choices: number[],\n    selected: boolean[],\n    res: number[][]\n): void {\n    // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    const duplicated = new Set();\n    choices.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\n        if (!selected[i] && !duplicated.has(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums: number[]): number[][] {\n    const res: number[][] = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_ii.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(\n  List<int> state,\n  List<int> choices,\n  List<bool> selected,\n  List<List<int>> res,\n) {\n  // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (state.length == choices.length) {\n    res.add(List.from(state));\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  Set<int> duplicated = {};\n  for (int i = 0; i < choices.length; i++) {\n    int 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\n    if (!selected[i] && !duplicated.contains(choice)) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n      selected[i] = true;\n      state.add(choice);\n      // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n      backtrack(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.removeLast();\n    }\n  }\n}\n\n/* \u5168\u6392\u5217 II */\nList<List<int>> permutationsII(List<int> nums) {\n  List<List<int>> res = [];\n  backtrack([], nums, List.filled(nums.length, false), res);\n  return 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\n    if state.len() == choices.len() {\n        res.push(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    let mut duplicated = HashSet::<i32>::new();\n    for i in 0..choices.len() {\n        let 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\n        if !selected[i] && !duplicated.contains(&choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.insert(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state.clone(), 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.remove(state.len() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nfn permutations_ii(nums: &mut [i32]) -> Vec<Vec<i32>> {\n    let mut res = Vec::new();\n    backtrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\n    res\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\n    if (stateSize == choicesSize) {\n        res[*resSize] = (int *)malloc(choicesSize * sizeof(int));\n        for (int i = 0; i < choicesSize; i++) {\n            res[*resSize][i] = state[i];\n        }\n        (*resSize)++;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    bool duplicated[MAX_SIZE] = {false};\n    for (int i = 0; i < choicesSize; i++) {\n        int 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\n        if (!selected[i] && !duplicated[choice]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated[choice] = true; // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state[stateSize] = choice;\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false;\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nint **permutationsII(int *nums, int numsSize, int *returnSize) {\n    int *state = (int *)malloc(numsSize * sizeof(int));\n    bool *selected = (bool *)malloc(numsSize * sizeof(bool));\n    for (int i = 0; i < numsSize; i++) {\n        selected[i] = false;\n    }\n    int **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n    *returnSize = 0;\n\n    backtrack(state, 0, nums, numsSize, selected, res, returnSize);\n\n    free(state);\n    free(selected);\n\n    return res;\n}\n
    permutations_ii.zig
    [class]{}-[func]{backtrack}\n\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\u907f\u514d\u67d0\u4e2a\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\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(\n    state: list[int],\n    target: int,\n    total: int,\n    choices: list[int],\n    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\n    if total == target:\n        res.append(list(state))\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i in range(len(choices)):\n        # \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if total + choices[i] > target:\n            continue\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.append(choices[i])\n        # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res)\n        # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop()\n\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\"\"\"\n    state = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    total = 0  # \u5b50\u96c6\u548c\n    res = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res)\n    return 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\n    if (total == target) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push_back(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop_back();\n    }\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) {\n    vector<int> state;       // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    int total = 0;           // \u5b50\u96c6\u548c\n    vector<vector<int>> res; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return 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\n    if (total == target) {\n        res.add(new ArrayList<>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.remove(state.size() - 1);\n    }\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) {\n    List<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    int total = 0; // \u5b50\u96c6\u548c\n    List<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return 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\n    if (total == target) {\n        res.Add(new List<int>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.Add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        Backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.RemoveAt(state.Count - 1);\n    }\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) {\n    List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    int total = 0; // \u5b50\u96c6\u548c\n    List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    Backtrack(state, target, total, nums, res);\n    return 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\n    if target == total {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i := 0; i < len(*choices); i++ {\n        // \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if total+(*choices)[i] > target {\n            continue\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\n        backtrackSubsetSumINaive(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\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums []int, target int) [][]int {\n    state := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    total := 0              // \u5b50\u96c6\u548c\n    res := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrackSubsetSumINaive(total, target, &state, &nums, &res)\n    return 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\n    if total == target {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for 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\n        if total + choices[i] > target {\n            continue\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.append(choices[i])\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.removeLast()\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums: [Int], target: Int) -> [[Int]] {\n    var state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let total = 0 // \u5b50\u96c6\u548c\n    var res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state: &state, target: target, total: total, choices: nums, res: &res)\n    return 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\n    if (total === target) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums, target) {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    const total = 0; // \u5b50\u96c6\u548c\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return res;\n}\n
    subset_sum_i_naive.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\n    state: number[],\n    target: number,\n    total: number,\n    choices: number[],\n    res: number[][]\n): void {\n    // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (total === target) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums: number[], target: number): number[][] {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    const total = 0; // \u5b50\u96c6\u548c\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return res;\n}\n
    subset_sum_i_naive.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\n  List<int> state,\n  int target,\n  int total,\n  List<int> choices,\n  List<List<int>> res,\n) {\n  // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (total == target) {\n    res.add(List.from(state));\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (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\n    if (total + choices[i] > target) {\n      continue;\n    }\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n    state.add(choices[i]);\n    // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n    backtrack(state, target, total + choices[i], choices, res);\n    // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n    state.removeLast();\n  }\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) {\n  List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n  int total = 0; // \u5143\u7d20\u548c\n  List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n  backtrack(state, target, total, nums, res);\n  return 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\n    if total == target {\n        res.push(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i in 0..choices.len() {\n        // \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if total + choices[i] > target {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\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>> {\n    let state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let total = 0; // \u5b50\u96c6\u548c\n    let mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, &mut res);\n    res\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\n    if (total == target) {\n        for (int i = 0; i < stateSize; i++) {\n            res[resSize][i] = state[i];\n        }\n        resColSizes[resSize++] = stateSize;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choicesSize; i++) {\n        // \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state[stateSize++] = choices[i];\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(target, total + choices[i], choices, choicesSize);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        stateSize--;\n    }\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) {\n    resSize = 0; // \u521d\u59cb\u5316\u89e3\u7684\u6570\u91cf\u4e3a0\n    backtrack(target, 0, nums, numsSize);\n}\n
    subset_sum_i_naive.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if target == 0:\n        res.append(list(state))\n        return\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    for 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\n        if target - choices[i] < 0:\n            break\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res)\n        # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop()\n\ndef subset_sum_i(nums: list[int], target: int) -> list[list[int]]:\n    \"\"\"\u6c42\u89e3\u5b50\u96c6\u548c I\"\"\"\n    state = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start = 0  # \u904d\u5386\u8d77\u59cb\u70b9\n    res = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res)\n    return 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\n    if (target == 0) {\n        res.push_back(state);\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push_back(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop_back();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvector<vector<int>> subsetSumI(vector<int> &nums, int target) {\n    vector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\n    vector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.add(new ArrayList<>(state));\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.remove(state.size() - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<Integer>> subsetSumI(int[] nums, int target) {\n    List<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Arrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.Add(new List<int>(state));\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.Add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        Backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.RemoveAt(state.Count - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> SubsetSumI(int[] nums, int target) {\n    List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Array.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    Backtrack(state, target, nums, start, res);\n    return 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\n    if target == 0 {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n        return\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    for 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\n        if target-(*choices)[i] < 0 {\n            break\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\n        backtrackSubsetSumI(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\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums []int, target int) [][]int {\n    state := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start := 0              // \u904d\u5386\u8d77\u59cb\u70b9\n    res := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrackSubsetSumI(start, target, &state, &nums, &res)\n    return 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\n    if target == 0 {\n        res.append(state)\n        return\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    for 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\n        if target - choices[i] < 0 {\n            break\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.removeLast()\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums: [Int], target: Int) -> [[Int]] {\n    var state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\n    var res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state: &state, target: target, choices: nums, start: start, res: &res)\n    return 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\n    if (target === 0) {\n        res.push([...state]);\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums, target) {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_i.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\n    state: number[],\n    target: number,\n    choices: number[],\n    start: number,\n    res: number[][]\n): void {\n    // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (target === 0) {\n        res.push([...state]);\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums: number[], target: number): number[][] {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_i.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\n  List<int> state,\n  int target,\n  List<int> choices,\n  int start,\n  List<List<int>> res,\n) {\n  // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (target == 0) {\n    res.add(List.from(state));\n    return;\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  for (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\n    if (target - choices[i] < 0) {\n      break;\n    }\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n    state.add(choices[i]);\n    // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n    backtrack(state, target - choices[i], choices, i, res);\n    // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n    state.removeLast();\n  }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> subsetSumI(List<int> nums, int target) {\n  List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n  nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n  int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n  List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n  backtrack(state, target, nums, start, res);\n  return 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\n    if target == 0 {\n        res.push(state);\n        return;\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    for 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\n        if target - choices[i] < 0 {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfn subset_sum_i(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\n    let state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    let mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, &mut res);\n    res\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\n    if (target == 0) {\n        for (int i = 0; i < stateSize; ++i) {\n            res[resSize][i] = state[i];\n        }\n        resColSizes[resSize++] = stateSize;\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state[stateSize] = choices[i];\n        stateSize++;\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(target - choices[i], choices, choicesSize, i);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        stateSize--;\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvoid subsetSumI(int *nums, int numsSize, int target) {\n    qsort(nums, numsSize, sizeof(int), cmp); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0;                           // \u904d\u5386\u8d77\u59cb\u70b9\n    backtrack(target, nums, numsSize, start);\n}\n
    subset_sum_i.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if target == 0:\n        res.append(list(state))\n        return\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\n    for 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\n        if target - choices[i] < 0:\n            break\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\n        if i > start and choices[i] == choices[i - 1]:\n            continue\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop()\n\ndef subset_sum_ii(nums: list[int], target: int) -> list[list[int]]:\n    \"\"\"\u6c42\u89e3\u5b50\u96c6\u548c II\"\"\"\n    state = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start = 0  # \u904d\u5386\u8d77\u59cb\u70b9\n    res = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res)\n    return 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\n    if (target == 0) {\n        res.push_back(state);\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push_back(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop_back();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvector<vector<int>> subsetSumII(vector<int> &nums, int target) {\n    vector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\n    vector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.add(new ArrayList<>(state));\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.remove(state.size() - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<Integer>> subsetSumII(int[] nums, int target) {\n    List<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Arrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.Add(new List<int>(state));\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.Add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        Backtrack(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\n        state.RemoveAt(state.Count - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> SubsetSumII(int[] nums, int target) {\n    List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Array.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    Backtrack(state, target, nums, start, res);\n    return 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\n    if target == 0 {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n        return\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\n    for 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\n        if target-(*choices)[i] < 0 {\n            break\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\n        if i > start && (*choices)[i] == (*choices)[i-1] {\n            continue\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\n        backtrackSubsetSumII(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\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums []int, target int) [][]int {\n    state := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start := 0              // \u904d\u5386\u8d77\u59cb\u70b9\n    res := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrackSubsetSumII(start, target, &state, &nums, &res)\n    return 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\n    if target == 0 {\n        res.append(state)\n        return\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\n    for 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\n        if target - choices[i] < 0 {\n            break\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\n        if i > start, choices[i] == choices[i - 1] {\n            continue\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.removeLast()\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums: [Int], target: Int) -> [[Int]] {\n    var state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\n    var res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state: &state, target: target, choices: nums, start: start, res: &res)\n    return 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\n    if (target === 0) {\n        res.push([...state]);\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] === choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums, target) {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_ii.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunction backtrack(\n    state: number[],\n    target: number,\n    choices: number[],\n    start: number,\n    res: number[][]\n): void {\n    // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (target === 0) {\n        res.push([...state]);\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] === choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums: number[], target: number): number[][] {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_ii.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(\n  List<int> state,\n  int target,\n  List<int> choices,\n  int start,\n  List<List<int>> res,\n) {\n  // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (target == 0) {\n    res.add(List.from(state));\n    return;\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\n  for (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\n    if (target - choices[i] < 0) {\n      break;\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\n    if (i > start && choices[i] == choices[i - 1]) {\n      continue;\n    }\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n    state.add(choices[i]);\n    // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n    backtrack(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\n    state.removeLast();\n  }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> subsetSumII(List<int> nums, int target) {\n  List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n  nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n  int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n  List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n  backtrack(state, target, nums, start, res);\n  return 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\n    if target == 0 {\n        res.push(state);\n        return;\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\n    for 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\n        if target - choices[i] < 0 {\n            break;\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\n        if i > start && choices[i] == choices[i - 1] {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfn subset_sum_ii(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\n    let state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    let mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, &mut res);\n    res\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\n    if (target == 0) {\n        for (int i = 0; i < stateSize; i++) {\n            res[resSize][i] = state[i];\n        }\n        resColSizes[resSize++] = stateSize;\n        return;\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\n    for (int i = start; i < choicesSize; i++) {\n        // \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\n        if (target - choices[i] < 0) {\n            continue;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state[stateSize] = choices[i];\n        stateSize++;\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(target - choices[i], choices, choicesSize, i + 1);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        stateSize--;\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvoid subsetSumII(int *nums, int numsSize, int target) {\n    // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    qsort(nums, numsSize, sizeof(int), cmp);\n    // \u5f00\u59cb\u56de\u6eaf\n    backtrack(target, nums, numsSize, 0);\n}\n
    subset_sum_ii.zig
    [class]{}-[func]{backtrack}\n\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\u6b21\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\u6b21\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\u5b83\u4e0e\u590d\u6742\u5ea6\u5206\u6790\u606f\u606f\u76f8\u5173\u3002\u56e0\u6b64\uff0c\u5728\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\"\"\"\n    res = 0\n    # \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i in range(1, n + 1):\n        res += i\n    return res\n
    iteration.cpp
    /* for \u5faa\u73af */\nint forLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; ++i) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.java
    /* for \u5faa\u73af */\nint forLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.cs
    /* for \u5faa\u73af */\nint ForLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.go
    /* for \u5faa\u73af */\nfunc forLoop(n int) int {\n    res := 0\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i := 1; i <= n; i++ {\n        res += i\n    }\n    return res\n}\n
    iteration.swift
    /* for \u5faa\u73af */\nfunc forLoop(n: Int) -> Int {\n    var res = 0\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i in 1 ... n {\n        res += i\n    }\n    return res\n}\n
    iteration.js
    /* for \u5faa\u73af */\nfunction forLoop(n) {\n    let res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.ts
    /* for \u5faa\u73af */\nfunction forLoop(n: number): number {\n    let res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.dart
    /* for \u5faa\u73af */\nint forLoop(int n) {\n  int res = 0;\n  // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n  for (int i = 1; i <= n; i++) {\n    res += i;\n  }\n  return res;\n}\n
    iteration.rs
    /* for \u5faa\u73af */\nfn for_loop(n: i32) -> i32 {\n    let mut res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i in 1..=n {\n        res += i;\n    }\n    res\n} \n
    iteration.c
    /* for \u5faa\u73af */\nint forLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.zig
    // for \u5faa\u73af\nfn forLoop(n: usize) i32 {\n    var res: i32 = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (1..n+1) |i| {\n        res = res + @as(i32, @intCast(i));\n    }\n    return res;\n} \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\"\"\"\n    res = 0\n    i = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    # \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while i <= n:\n        res += i\n        i += 1  # \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    return res\n
    iteration.cpp
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.java
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.cs
    /* while \u5faa\u73af */\nint WhileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.go
    /* while \u5faa\u73af */\nfunc whileLoop(n int) int {\n    res := 0\n    // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    i := 1\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i <= n {\n        res += i\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++\n    }\n    return res\n}\n
    iteration.swift
    /* while \u5faa\u73af */\nfunc whileLoop(n: Int) -> Int {\n    var res = 0\n    var i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while i <= n {\n        res += i\n        i += 1 // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res\n}\n
    iteration.js
    /* while \u5faa\u73af */\nfunction whileLoop(n) {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.ts
    /* while \u5faa\u73af */\nfunction whileLoop(n: number): number {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.dart
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n  int res = 0;\n  int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n  // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n  while (i <= n) {\n    res += i;\n    i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n  }\n  return res;\n}\n
    iteration.rs
    /* while \u5faa\u73af */\nfn while_loop(n: i32) -> i32 {\n    let mut res = 0;\n    let mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while i <= n {\n        res += i;\n        i += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    res\n}\n
    iteration.c
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.zig
    // while \u5faa\u73af\nfn whileLoop(n: i32) i32 {\n    var res: i32 = 0;\n    var i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += @intCast(i);\n        i += 1;\n    }\n    return 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\"\"\"\n    res = 0\n    i = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    # \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while i <= n:\n        res += i\n        # \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1\n        i *= 2\n    return res\n
    iteration.cpp
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.java
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.cs
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint WhileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, 4, 5...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1; \n        i *= 2;\n    }\n    return res;\n}\n
    iteration.go
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n int) int {\n    res := 0\n    // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    i := 1\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    for i <= n {\n        res += i\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++\n        i *= 2\n    }\n    return res\n}\n
    iteration.swift
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n: Int) -> Int {\n    var res = 0\n    var i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while i <= n {\n        res += i\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1\n        i *= 2\n    }\n    return res\n}\n
    iteration.js
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n) {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.ts
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n: number): number {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.dart
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n  int res = 0;\n  int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n  // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n  while (i <= n) {\n    res += i;\n    // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    i++;\n    i *= 2;\n  }\n  return res;\n}\n
    iteration.rs
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfn while_loop_ii(n: i32) -> i32 {\n    let mut res = 0;\n    let mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while i <= n {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1;\n        i *= 2;\n    }\n    res\n}\n
    iteration.c
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.zig
    //  while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09\nfn whileLoopII(n: i32) i32 {\n    var res: i32 = 0;\n    var i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += @intCast(i);\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1;\n        i *= 2;\n    }\n    return 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\"\"\"\n    res = \"\"\n    # \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i in range(1, n + 1):\n        # \u5faa\u73af j = 1, 2, ..., n-1, n\n        for j in range(1, n + 1):\n            res += f\"({i}, {j}), \"\n    return res\n
    iteration.cpp
    /* \u53cc\u5c42 for \u5faa\u73af */\nstring nestedForLoop(int n) {\n    ostringstream res;\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; ++i) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; ++j) {\n            res << \"(\" << i << \", \" << j << \"), \";\n        }\n    }\n    return res.str();\n}\n
    iteration.java
    /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\n    StringBuilder res = new StringBuilder();\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; j++) {\n            res.append(\"(\" + i + \", \" + j + \"), \");\n        }\n    }\n    return res.toString();\n}\n
    iteration.cs
    /* \u53cc\u5c42 for \u5faa\u73af */\nstring NestedForLoop(int n) {\n    StringBuilder res = new();\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; j++) {\n            res.Append($\"({i}, {j}), \");\n        }\n    }\n    return res.ToString();\n}\n
    iteration.go
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n int) string {\n    res := \"\"\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i := 1; i <= n; i++ {\n        for j := 1; j <= n; j++ {\n            // \u5faa\u73af j = 1, 2, ..., n-1, n\n            res += fmt.Sprintf(\"(%d, %d), \", i, j)\n        }\n    }\n    return res\n}\n
    iteration.swift
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n: Int) -> String {\n    var res = \"\"\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i in 1 ... n {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for j in 1 ... n {\n            res.append(\"(\\(i), \\(j)), \")\n        }\n    }\n    return res\n}\n
    iteration.js
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n) {\n    let res = '';\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (let j = 1; j <= n; j++) {\n            res += `(${i}, ${j}), `;\n        }\n    }\n    return res;\n}\n
    iteration.ts
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n: number): string {\n    let res = '';\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (let j = 1; j <= n; j++) {\n            res += `(${i}, ${j}), `;\n        }\n    }\n    return res;\n}\n
    iteration.dart
    /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\n  String res = \"\";\n  // \u5faa\u73af i = 1, 2, ..., n-1, n\n  for (int i = 1; i <= n; i++) {\n    // \u5faa\u73af j = 1, 2, ..., n-1, n\n    for (int j = 1; j <= n; j++) {\n      res += \"($i, $j), \";\n    }\n  }\n  return res;\n}\n
    iteration.rs
    /* \u53cc\u5c42 for \u5faa\u73af */\nfn nested_for_loop(n: i32) -> String {\n    let mut res = vec![];\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i in 1..=n {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for j in 1..=n {\n            res.push(format!(\"({}, {}), \", i, j));\n        }\n    }\n    res.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\n    int size = n * n * 26 + 1;\n    char *res = malloc(size * sizeof(char));\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; j++) {\n            char tmp[26];\n            snprintf(tmp, sizeof(tmp), \"(%d, %d), \", i, j);\n            strncat(res, tmp, size - strlen(res) - 1);\n        }\n    }\n    return res;\n}\n
    iteration.zig
    // \u53cc\u5c42 for \u5faa\u73af\nfn nestedForLoop(allocator: Allocator, n: usize) ![]const u8 {\n    var res = std.ArrayList(u8).init(allocator);\n    defer res.deinit();\n    var buffer: [20]u8 = undefined;\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (1..n+1) |i| {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (1..n+1) |j| {\n            var _str = try std.fmt.bufPrint(&buffer, \"({d}, {d}), \", .{i, j});\n            try res.appendSlice(_str);\n        }\n    }\n    return 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\n    if n == 1:\n        return 1\n    # \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    res = recur(n - 1)\n    # \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res\n
    recursion.cpp
    /* \u9012\u5f52 */\nint recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.java
    /* \u9012\u5f52 */\nint recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.cs
    /* \u9012\u5f52 */\nint Recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = Recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.go
    /* \u9012\u5f52 */\nfunc recur(n int) int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 1 {\n        return 1\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    res := recur(n - 1)\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res\n}\n
    recursion.swift
    /* \u9012\u5f52 */\nfunc recur(n: Int) -> Int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 1 {\n        return 1\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    let res = recur(n: n - 1)\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res\n}\n
    recursion.js
    /* \u9012\u5f52 */\nfunction recur(n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 1) return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    const res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.ts
    /* \u9012\u5f52 */\nfunction recur(n: number): number {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 1) return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    const res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.dart
    /* \u9012\u5f52 */\nint recur(int n) {\n  // \u7ec8\u6b62\u6761\u4ef6\n  if (n == 1) return 1;\n  // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n  int res = recur(n - 1);\n  // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n  return n + res;\n}\n
    recursion.rs
    /* \u9012\u5f52 */\nfn recur(n: i32) -> i32 {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 1 {\n        return 1;\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    let res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    n + res\n}\n
    recursion.c
    /* \u9012\u5f52 */\nint recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.zig
    // \u9012\u5f52\u51fd\u6570\nfn recur(n: i32) i32 {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1) {\n        return 1;\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    var res: i32 = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return 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\n    if n == 0:\n        return res\n    # \u5c3e\u9012\u5f52\u8c03\u7528\n    return tail_recur(n - 1, res + n)\n
    recursion.cpp
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.java
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.cs
    /* \u5c3e\u9012\u5f52 */\nint TailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return TailRecur(n - 1, res + n);\n}\n
    recursion.go
    /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n int, res int) int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 0 {\n        return res\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n-1, res+n)\n}\n
    recursion.swift
    /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n: Int, res: Int) -> Int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 0 {\n        return res\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n: n - 1, res: res + n)\n}\n
    recursion.js
    /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n, res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 0) return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.ts
    /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n: number, res: number): number {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 0) return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.dart
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n  // \u7ec8\u6b62\u6761\u4ef6\n  if (n == 0) return res;\n  // \u5c3e\u9012\u5f52\u8c03\u7528\n  return 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\n    if n == 0 {\n        return res;\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    tail_recur(n - 1, res + n)\n}\n
    recursion.c
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return 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\n    if (n == 0) {\n        return res;\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return 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\n    if n == 1 or n == 2:\n        return n - 1\n    # \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    res = fib(n - 1) + fib(n - 2)\n    # \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = Fib(n - 1) + Fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if n == 1 || n == 2 {\n        return n - 1\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    res := fib(n-1) + fib(n-2)\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if n == 1 || n == 2 {\n        return n - 1\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    let res = fib(n: n - 1) + fib(n: n - 2)\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n === 1 || n === 2) return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    const res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n === 1 || n === 2) return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    const res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n  if (n == 1 || n == 2) return n - 1;\n  // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n  int res = fib(n - 1) + fib(n - 2);\n  // \u8fd4\u56de\u7ed3\u679c f(n)\n  return 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\n    if n == 1 || n == 2 {\n        return n - 1;\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    let res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c\n    res\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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 or n == 2) {\n        return n - 1;\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    var res: i32 = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\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\u5f02\u66f2\u540c\u5de5\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\u88ab\u4ece\u201c\u8c03\u7528\u6808\u201d\u4e0a\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\n    stack = []\n    res = 0\n    # \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i in range(n, 0, -1):\n        # \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.append(i)\n    # \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while stack:\n        # \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop()\n    # res = 1+2+3+...+n\n    return 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\n    stack<int> stack;\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (!stack.empty()) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.top();\n        stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n    Stack<Integer> stack = new Stack<>();\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (!stack.isEmpty()) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n    Stack<int> stack = new();\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.Push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (stack.Count > 0) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.Pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n    stack := list.New()\n    res := 0\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i := n; i > 0; i-- {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.PushBack(i)\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    for stack.Len() != 0 {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.Back().Value.(int)\n        stack.Remove(stack.Back())\n    }\n    // res = 1+2+3+...+n\n    return 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\n    var stack: [Int] = []\n    var res = 0\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i in stride(from: n, to: 0, by: -1) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.append(i)\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while !stack.isEmpty {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.removeLast()\n    }\n    // res = 1+2+3+...+n\n    return 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\n    const stack = [];\n    let res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (let i = 1; i <= n; i++) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (stack.length) { \n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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 \n    const stack: number[] = [];\n    let res: number = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (let i = 1; i <= n; i++) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (stack.length) { \n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n  List<int> stack = [];\n  int res = 0;\n  // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n  for (int i = n; i > 0; i--) {\n    // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n    stack.add(i);\n  }\n  // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n  while (!stack.isEmpty) {\n    // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n    res += stack.removeLast();\n  }\n  // res = 1+2+3+...+n\n  return 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\n    let mut stack = Vec::new();\n    let mut res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i in (1..=n).rev() {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while !stack.is_empty() {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop().unwrap();\n    }\n    // res = 1+2+3+...+n\n    res\n}\n
    recursion.c
    /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n    int stack[1000]; // \u501f\u52a9\u4e00\u4e2a\u5927\u6570\u7ec4\u6765\u6a21\u62df\u6808\n    int top = -1;    // \u6808\u9876\u7d22\u5f15\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack[1 + top++] = i;\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (top >= 0) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack[top--];\n    }\n    // res = 1+2+3+...+n\n    return 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\n    var stack: [n]i32 = undefined;\n    var res: i32 = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    var i: usize = n;\n    while (i > 0) {\n        stack[i - 1] = @intCast(i);\n        i -= 1;\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    var index: usize = n;\n    while (index > 0) {\n        index -= 1;\n        res += stack[index];\n    }\n    // res = 1+2+3+...+n\n    return res;\n}\n

    \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u5f53\u9012\u5f52\u8f6c\u5316\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\u5316\uff0c\u4f46\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\u81f3\u5173\u91cd\u8981\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\"\"\"\n    def __init__(self, x: int):\n        self.val: int = x              # \u8282\u70b9\u503c\n        self.next: Node | None = None  # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n\ndef function() -> int:\n    \"\"\"\u51fd\u6570\"\"\"\n    # \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n\ndef algorithm(n) -> int:  # \u8f93\u5165\u6570\u636e\n    A = 0                 # \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff0c\u4e00\u822c\u7528\u5927\u5199\u5b57\u6bcd\u8868\u793a\uff09\n    b = 0                 # \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    node = Node(0)        # \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    c = function()        # \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return A + b + c      # \u8f93\u51fa\u6570\u636e\n
    /* \u7ed3\u6784\u4f53 */\nstruct Node {\n    int val;\n    Node *next;\n    Node(int x) : val(x), next(nullptr) {}\n};\n\n/* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\n    const int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    Node* node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    int c = func();           // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    int val;\n    Node next;\n    Node(int x) { val = x; }\n}\n\n/* \u51fd\u6570 */\nint function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\n    final int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    Node node = new Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    int c = function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node(int x) {\n    int val = x;\n    Node next;\n}\n\n/* \u51fd\u6570 */\nint Function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint Algorithm(int n) {        // \u8f93\u5165\u6570\u636e\n    const int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    Node node = new(0);       // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    int c = Function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7ed3\u6784\u4f53 */\ntype node struct {\n    val  int\n    next *node\n}\n\n/* \u521b\u5efa node \u7ed3\u6784\u4f53  */\nfunc newNode(val int) *node {\n    return &node{val: val}\n}\n\n/* \u51fd\u6570 */\nfunc function() int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n}\n\nfunc algorithm(n int) int { // \u8f93\u5165\u6570\u636e\n    const a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    b := 0                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    newNode(0)              // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    c := function()         // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c        // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    var val: Int\n    var next: Node?\n\n    init(x: Int) {\n        val = x\n    }\n}\n\n/* \u51fd\u6570 */\nfunc function() -> Int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n}\n\nfunc algorithm(n: Int) -> Int { // \u8f93\u5165\u6570\u636e\n    let a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    var b = 0             // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    let node = Node(x: 0) // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    let c = function()    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c      // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    val;\n    next;\n    constructor(val) {\n        this.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\n        this.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n\n/* \u51fd\u6570 */\nfunction constFunc() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\nfunction algorithm(n) {       // \u8f93\u5165\u6570\u636e\n    const a = 0;              // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    let b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    const node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    const c = constFunc();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    val: number;\n    next: Node | null;\n    constructor(val?: number) {\n        this.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\n        this.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n\n/* \u51fd\u6570 */\nfunction constFunc(): number {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\nfunction algorithm(n: number): number { // \u8f93\u5165\u6570\u636e\n    const a = 0;                        // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    let b = 0;                          // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    const node = new Node(0);           // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    const c = constFunc();              // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;                   // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n  int val;\n  Node next;\n  Node(this.val, [this.next]);\n}\n\n/* \u51fd\u6570 */\nint function() {\n  // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n  return 0;\n}\n\nint algorithm(int n) {  // \u8f93\u5165\u6570\u636e\n  const int a = 0;      // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n  int b = 0;            // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n  Node node = Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n  int c = function();   // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n  return a + b + c;     // \u8f93\u51fa\u6570\u636e\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* \u7ed3\u6784\u4f53 */\nstruct Node {\n    val: i32,\n    next: Option<Rc<RefCell<Node>>>,\n}\n\n/* \u521b\u5efa Node \u7ed3\u6784\u4f53 */\nimpl Node {\n    fn new(val: i32) -> Self {\n        Self { val: val, next: None }\n    }\n}\n\n/* \u51fd\u6570 */\nfn function() -> i32 {      \n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nfn algorithm(n: i32) -> i32 {       // \u8f93\u5165\u6570\u636e\n    const a: i32 = 0;               // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    let mut b = 0;                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    let node = Node::new(0);        // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    let c = function();             // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;               // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint algorithm(int n) { // \u8f93\u5165\u6570\u636e\n    const int a = 0;   // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;         // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    int c = func();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return 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):\n    a = 0               # O(1)\n    b = [0] * 10000     # O(1)\n    if n > 10:\n        nums = [0] * n  # O(n)\n
    void algorithm(int n) {\n    int a = 0;               // O(1)\n    vector<int> b(10000);    // O(1)\n    if (n > 10)\n        vector<int> nums(n); // O(n)\n}\n
    void algorithm(int n) {\n    int a = 0;                   // O(1)\n    int[] b = new int[10000];    // O(1)\n    if (n > 10)\n        int[] nums = new int[n]; // O(n)\n}\n
    void Algorithm(int n) {\n    int a = 0;                   // O(1)\n    int[] b = new int[10000];    // O(1)\n    if (n > 10) {\n        int[] nums = new int[n]; // O(n)\n    }\n}\n
    func algorithm(n int) {\n    a := 0                      // O(1)\n    b := make([]int, 10000)     // O(1)\n    var nums []int\n    if n > 10 {\n        nums := make([]int, n)  // O(n)\n    }\n    fmt.Println(a, b, nums)\n}\n
    func algorithm(n: Int) {\n    let a = 0 // O(1)\n    let b = Array(repeating: 0, count: 10000) // O(1)\n    if n > 10 {\n        let nums = Array(repeating: 0, count: n) // O(n)\n    }\n}\n
    function algorithm(n) {\n    const a = 0;                   // O(1)\n    const b = new Array(10000);    // O(1)\n    if (n > 10) {\n        const nums = new Array(n); // O(n)\n    }\n}\n
    function algorithm(n: number): void {\n    const a = 0;                   // O(1)\n    const b = new Array(10000);    // O(1)\n    if (n > 10) {\n        const nums = new Array(n); // O(n)\n    }\n}\n
    void algorithm(int n) {\n  int a = 0;                            // O(1)\n  List<int> b = List.filled(10000, 0);  // O(1)\n  if (n > 10) {\n    List<int> nums = List.filled(n, 0); // O(n)\n  }\n}\n
    fn algorithm(n: i32) {\n    let a = 0;                              // O(1)\n    let b = [0; 10000];                     // O(1)\n    if n > 10 {\n        let nums = vec![0; n as usize];     // O(n)\n    }\n}\n
    void algorithm(int n) {\n    int a = 0;               // O(1)\n    int b[10000];            // O(1)\n    if (n > 10)\n        int 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\n    return 0\n\ndef loop(n: int):\n    \"\"\"\u5faa\u73af\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1)\"\"\"\n    for _ in range(n):\n        function()\n\ndef recur(n: int) -> int:\n    \"\"\"\u9012\u5f52\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\"\"\"\n    if n == 1: return\n    return recur(n - 1)\n
    int func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n    if (n == 1) return;\n    return recur(n - 1);\n}\n
    int function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n    for (int i = 0; i < n; i++) {\n        function();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n    if (n == 1) return;\n    return recur(n - 1);\n}\n
    int Function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid Loop(int n) {\n    for (int i = 0; i < n; i++) {\n        Function();\n    }\n}\n/* \u9012\u5f52 O(n) */\nint Recur(int n) {\n    if (n == 1) return 1;\n    return Recur(n - 1);\n}\n
    func function() int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0\n}\n\n/* \u5faa\u73af O(1) */\nfunc loop(n int) {\n    for i := 0; i < n; i++ {\n        function()\n    }\n}\n\n/* \u9012\u5f52 O(n) */\nfunc recur(n int) {\n    if n == 1 {\n        return\n    }\n    recur(n - 1)\n}\n
    @discardableResult\nfunc function() -> Int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0\n}\n\n/* \u5faa\u73af O(1) */\nfunc loop(n: Int) {\n    for _ in 0 ..< n {\n        function()\n    }\n}\n\n/* \u9012\u5f52 O(n) */\nfunc recur(n: Int) {\n    if n == 1 {\n        return\n    }\n    recur(n: n - 1)\n}\n
    function constFunc() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n) {\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n) {\n    if (n === 1) return;\n    return recur(n - 1);\n}\n
    function constFunc(): number {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n: number): void {\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n: number): void {\n    if (n === 1) return;\n    return recur(n - 1);\n}\n
    int function() {\n  // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n  return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n  for (int i = 0; i < n; i++) {\n    function();\n  }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n  if (n == 1) return;\n  return recur(n - 1);\n}\n
    fn function() -> i32 {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nfn loop(n: i32) {\n    for i in 0..n {\n        function();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(n: i32) {\n    if n == 1 {\n        return;\n    }\n    recur(n - 1);\n}\n
    int func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n    if (n == 1) return;\n    return 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\n    return 0\n\ndef constant(n: int):\n    \"\"\"\u5e38\u6570\u9636\"\"\"\n    # \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    a = 0\n    nums = [0] * 10000\n    node = ListNode(0)\n    # \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in range(n):\n        c = 0\n    # \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in range(n):\n        function()\n
    space_complexity.cpp
    /* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const int a = 0;\n    int b = 0;\n    vector<int> nums(10000);\n    ListNode node(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n
    space_complexity.java
    /* \u51fd\u6570 */\nint function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    final int a = 0;\n    int b = 0;\n    int[] nums = new int[10000];\n    ListNode node = new ListNode(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        function();\n    }\n}\n
    space_complexity.cs
    /* \u51fd\u6570 */\nint Function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid Constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    int a = 0;\n    int b = 0;\n    int[] nums = new int[10000];\n    ListNode node = new(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        Function();\n    }\n}\n
    space_complexity.go
    /* \u51fd\u6570 */\nfunc function() int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n}\n\n/* \u5e38\u6570\u9636 */\nfunc spaceConstant(n int) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const a = 0\n    b := 0\n    nums := make([]int, 10000)\n    ListNode := newNode(0)\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    var c int\n    for i := 0; i < n; i++ {\n        c = 0\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for i := 0; i < n; i++ {\n        function()\n    }\n    fmt.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\n    return 0\n}\n\n/* \u5e38\u6570\u9636 */\nfunc constant(n: Int) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    let a = 0\n    var b = 0\n    let nums = Array(repeating: 0, count: 10000)\n    let node = ListNode(x: 0)\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in 0 ..< n {\n        let c = 0\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in 0 ..< n {\n        function()\n    }\n}\n
    space_complexity.js
    /* \u51fd\u6570 */\nfunction constFunc() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nfunction constant(n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const a = 0;\n    const b = 0;\n    const nums = new Array(10000);\n    const node = new ListNode(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        const c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n
    space_complexity.ts
    /* \u51fd\u6570 */\nfunction constFunc(): number {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\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\n    const a = 0;\n    const b = 0;\n    const nums = new Array(10000);\n    const node = new ListNode(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        const c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n
    space_complexity.dart
    /* \u51fd\u6570 */\nint function() {\n  // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n  return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n  // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n  final int a = 0;\n  int b = 0;\n  List<int> nums = List.filled(10000, 0);\n  ListNode node = ListNode(0);\n  // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n  for (var i = 0; i < n; i++) {\n    int c = 0;\n  }\n  // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n  for (var i = 0; i < n; i++) {\n    function();\n  }\n}\n
    space_complexity.rs
    /* \u51fd\u6570 */\nfn function() ->i32 {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\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\n    const A: i32 = 0;\n    let b = 0;\n    let nums = vec![0; 10000];\n    let node = ListNode::new(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for i in 0..n {\n        let c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for i in 0..n {\n        function();\n    }\n}\n
    space_complexity.c
    /* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const int a = 0;\n    int b = 0;\n    int nums[1000];\n    ListNode *node = newListNode(0);\n    free(node);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n
    space_complexity.zig
    // \u51fd\u6570\nfn function() i32 {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\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\n    const a: i32 = 0;\n    var b: i32 = 0;\n    var nums = [_]i32{0}**10000;\n    var node = inc.ListNode(i32){.val = 0};\n    var i: i32 = 0;\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    while (i < n) : (i += 1) {\n        var c: i32 = 0;\n        _ = c;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    i = 0;\n    while (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\n    nums = [0] * n\n    # \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    hmap = dict[int, str]()\n    for i in range(n):\n        hmap[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\n    vector<int> nums(n);\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    vector<ListNode> nodes;\n    for (int i = 0; i < n; i++) {\n        nodes.push_back(ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    unordered_map<int, string> map;\n    for (int i = 0; i < n; i++) {\n        map[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\n    int[] nums = new int[n];\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    List<ListNode> nodes = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n        nodes.add(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    Map<Integer, String> map = new HashMap<>();\n    for (int i = 0; i < n; i++) {\n        map.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\n    int[] nums = new int[n];\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    List<ListNode> nodes = [];\n    for (int i = 0; i < n; i++) {\n        nodes.Add(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    Dictionary<int, string> map = [];\n    for (int i = 0; i < n; i++) {\n        map.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\n    var nodes []*node\n    for i := 0; i < n; i++ {\n        nodes = append(nodes, newNode(i))\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    m := make(map[int]string, n)\n    for i := 0; i < n; i++ {\n        m[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\n    let nums = Array(repeating: 0, count: n)\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let nodes = (0 ..< n).map { ListNode(x: $0) }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let 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\n    const nums = new Array(n);\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const nodes = [];\n    for (let i = 0; i < n; i++) {\n        nodes.push(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const map = new Map();\n    for (let i = 0; i < n; i++) {\n        map.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\n    const nums = new Array(n);\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const nodes: ListNode[] = [];\n    for (let i = 0; i < n; i++) {\n        nodes.push(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const map = new Map();\n    for (let i = 0; i < n; i++) {\n        map.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\n  List<int> nums = List.filled(n, 0);\n  // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n  List<ListNode> nodes = [];\n  for (var i = 0; i < n; i++) {\n    nodes.add(ListNode(i));\n  }\n  // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n  Map<int, String> map = HashMap();\n  for (var i = 0; i < n; i++) {\n    map.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\n    let mut nums = vec![0; n as usize];\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let mut nodes = Vec::new();\n    for i in 0..n {\n        nodes.push(ListNode::new(i))\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let mut map = HashMap::new();\n    for i in 0..n {\n        map.insert(i, i.to_string());\n    }\n}\n
    space_complexity.c
    /* \u54c8\u5e0c\u8868 */\ntypedef struct {\n    int key;\n    int val;\n    UT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n\n/* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n    // \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\n    int *nums = malloc(sizeof(int) * n);\n    free(nums);\n\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    ListNode **nodes = malloc(sizeof(ListNode *) * n);\n    for (int i = 0; i < n; i++) {\n        nodes[i] = newListNode(i);\n    }\n    // \u5185\u5b58\u91ca\u653e\n    for (int i = 0; i < n; i++) {\n        free(nodes[i]);\n    }\n    free(nodes);\n\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    HashTable *h = NULL;\n    for (int i = 0; i < n; i++) {\n        HashTable *tmp = malloc(sizeof(HashTable));\n        tmp->key = i;\n        tmp->val = i;\n        HASH_ADD_INT(h, key, tmp);\n    }\n\n    // \u5185\u5b58\u91ca\u653e\n    HashTable *curr, *tmp;\n    HASH_ITER(hh, h, curr, tmp) {\n        HASH_DEL(h, curr);\n        free(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\n    var nums = [_]i32{0}**n;\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    var nodes = std.ArrayList(i32).init(std.heap.page_allocator);\n    defer nodes.deinit();\n    var i: i32 = 0;\n    while (i < n) : (i += 1) {\n        try nodes.append(i);\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    var map = std.AutoArrayHashMap(i32, []const u8).init(std.heap.page_allocator);\n    defer map.deinit();\n    var j: i32 = 0;\n    while (j < n) : (j += 1) {\n        const string = try std.fmt.allocPrint(std.heap.page_allocator, \"{d}\", .{j});\n        defer std.heap.page_allocator.free(string);\n        try 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\"\"\"\n    print(\"\u9012\u5f52 n =\", n)\n    if n == 1:\n        return\n    linear_recur(n - 1)\n
    space_complexity.cpp
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n    cout << \"\u9012\u5f52 n = \" << n << endl;\n    if (n == 1)\n        return;\n    linearRecur(n - 1);\n}\n
    space_complexity.java
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n    System.out.println(\"\u9012\u5f52 n = \" + n);\n    if (n == 1)\n        return;\n    linearRecur(n - 1);\n}\n
    space_complexity.cs
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid LinearRecur(int n) {\n    Console.WriteLine(\"\u9012\u5f52 n = \" + n);\n    if (n == 1) return;\n    LinearRecur(n - 1);\n}\n
    space_complexity.go
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceLinearRecur(n int) {\n    fmt.Println(\"\u9012\u5f52 n =\", n)\n    if n == 1 {\n        return\n    }\n    spaceLinearRecur(n - 1)\n}\n
    space_complexity.swift
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc linearRecur(n: Int) {\n    print(\"\u9012\u5f52 n = \\(n)\")\n    if n == 1 {\n        return\n    }\n    linearRecur(n: n - 1)\n}\n
    space_complexity.js
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n) {\n    console.log(`\u9012\u5f52 n = ${n}`);\n    if (n === 1) return;\n    linearRecur(n - 1);\n}\n
    space_complexity.ts
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n: number): void {\n    console.log(`\u9012\u5f52 n = ${n}`);\n    if (n === 1) return;\n    linearRecur(n - 1);\n}\n
    space_complexity.dart
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n  print('\u9012\u5f52 n = $n');\n  if (n == 1) return;\n  linearRecur(n - 1);\n}\n
    space_complexity.rs
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn linear_recur(n: i32) {\n    println!(\"\u9012\u5f52 n = {}\", n);\n    if n == 1 {return};\n    linear_recur(n - 1);\n}\n
    space_complexity.c
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n    printf(\"\u9012\u5f52 n = %d\\r\\n\", n);\n    if (n == 1)\n        return;\n    linearRecur(n - 1);\n}\n
    space_complexity.zig
    // \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn linearRecur(comptime n: i32) void {\n    std.debug.print(\"\u9012\u5f52 n = {}\\n\", .{n});\n    if (n == 1) return;\n    linearRecur(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\n    num_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\n    vector<vector<int>> numMatrix;\n    for (int i = 0; i < n; i++) {\n        vector<int> tmp;\n        for (int j = 0; j < n; j++) {\n            tmp.push_back(0);\n        }\n        numMatrix.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\n    int[][] numMatrix = new int[n][n];\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    List<List<Integer>> numList = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n        List<Integer> tmp = new ArrayList<>();\n        for (int j = 0; j < n; j++) {\n            tmp.add(0);\n        }\n        numList.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\n    int[,] numMatrix = new int[n, n];\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    List<List<int>> numList = [];\n    for (int i = 0; i < n; i++) {\n        List<int> tmp = [];\n        for (int j = 0; j < n; j++) {\n            tmp.Add(0);\n        }\n        numList.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\n    numMatrix := make([][]int, n)\n    for i := 0; i < n; i++ {\n        numMatrix[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\n    let 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\n    const numMatrix = Array(n)\n        .fill(null)\n        .map(() => Array(n).fill(null));\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    const numList = [];\n    for (let i = 0; i < n; i++) {\n        const tmp = [];\n        for (let j = 0; j < n; j++) {\n            tmp.push(0);\n        }\n        numList.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\n    const numMatrix = Array(n)\n        .fill(null)\n        .map(() => Array(n).fill(null));\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    const numList = [];\n    for (let i = 0; i < n; i++) {\n        const tmp = [];\n        for (let j = 0; j < n; j++) {\n            tmp.push(0);\n        }\n        numList.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\n  List<List<int>> numMatrix = List.generate(n, (_) => List.filled(n, 0));\n  // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n  List<List<int>> numList = [];\n  for (var i = 0; i < n; i++) {\n    List<int> tmp = [];\n    for (int j = 0; j < n; j++) {\n      tmp.add(0);\n    }\n    numList.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\n    let num_matrix = vec![vec![0; n as usize]; n as usize];\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    let mut num_list = Vec::new();\n    for i in 0..n {\n        let mut tmp = Vec::new();\n        for j in 0..n {\n            tmp.push(0);\n        }\n        num_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\n    int **numMatrix = malloc(sizeof(int *) * n);\n    for (int i = 0; i < n; i++) {\n        int *tmp = malloc(sizeof(int) * n);\n        for (int j = 0; j < n; j++) {\n            tmp[j] = 0;\n        }\n        numMatrix[i] = tmp;\n    }\n\n    // \u5185\u5b58\u91ca\u653e\n    for (int i = 0; i < n; i++) {\n        free(numMatrix[i]);\n    }\n    free(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\n    var nodes = std.ArrayList(std.ArrayList(i32)).init(std.heap.page_allocator);\n    defer nodes.deinit();\n    var i: i32 = 0;\n    while (i < n) : (i += 1) {\n        var tmp = std.ArrayList(i32).init(std.heap.page_allocator);\n        defer tmp.deinit();\n        var j: i32 = 0;\n        while (j < n) : (j += 1) {\n            try tmp.append(0);\n        }\n        try 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\"\"\"\n    if n <= 0:\n        return 0\n    # \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    nums = [0] * n\n    return quadratic_recur(n - 1)\n
    space_complexity.cpp
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n    if (n <= 0)\n        return 0;\n    vector<int> nums(n);\n    cout << \"\u9012\u5f52 n = \" << n << \" \u4e2d\u7684 nums \u957f\u5ea6 = \" << nums.size() << endl;\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.java
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n    if (n <= 0)\n        return 0;\n    // \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    int[] nums = new int[n];\n    System.out.println(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.length);\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.cs
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint QuadraticRecur(int n) {\n    if (n <= 0) return 0;\n    int[] nums = new int[n];\n    Console.WriteLine(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.Length);\n    return QuadraticRecur(n - 1);\n}\n
    space_complexity.go
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceQuadraticRecur(n int) int {\n    if n <= 0 {\n        return 0\n    }\n    nums := make([]int, n)\n    fmt.Printf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d \\n\", n, len(nums))\n    return spaceQuadraticRecur(n - 1)\n}\n
    space_complexity.swift
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\n@discardableResult\nfunc quadraticRecur(n: Int) -> Int {\n    if n <= 0 {\n        return 0\n    }\n    // \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    let nums = Array(repeating: 0, count: n)\n    print(\"\u9012\u5f52 n = \\(n) \u4e2d\u7684 nums \u957f\u5ea6 = \\(nums.count)\")\n    return quadraticRecur(n: n - 1)\n}\n
    space_complexity.js
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n) {\n    if (n <= 0) return 0;\n    const nums = new Array(n);\n    console.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.ts
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n: number): number {\n    if (n <= 0) return 0;\n    const nums = new Array(n);\n    console.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.dart
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n  if (n <= 0) return 0;\n  List<int> nums = List.filled(n, 0);\n  print('\u9012\u5f52 n = $n \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}');\n  return quadraticRecur(n - 1);\n}\n
    space_complexity.rs
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn quadratic_recur(n: i32) -> i32 {\n    if n <= 0 {return 0};\n    // \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    let nums = vec![0; n as usize];\n    println!(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\", n, nums.len());\n    return quadratic_recur(n - 1);\n}\n
    space_complexity.c
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n    if (n <= 0)\n        return 0;\n    int *nums = malloc(sizeof(int) * n);\n    printf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d\\r\\n\", n, n);\n    int res = quadraticRecur(n - 1);\n    free(nums);\n    return res;\n}\n
    space_complexity.zig
    // \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn quadraticRecur(comptime n: i32) i32 {\n    if (n <= 0) return 0;\n    var nums = [_]i32{0}**n;\n    std.debug.print(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\\n\", .{n, nums.len});\n    return 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\u5c42\u6570\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\"\"\"\n    if n == 0:\n        return None\n    root = TreeNode(0)\n    root.left = build_tree(n - 1)\n    root.right = build_tree(n - 1)\n    return root\n
    space_complexity.cpp
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\n    if (n == 0)\n        return nullptr;\n    TreeNode *root = new TreeNode(0);\n    root->left = buildTree(n - 1);\n    root->right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.java
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode buildTree(int n) {\n    if (n == 0)\n        return null;\n    TreeNode root = new TreeNode(0);\n    root.left = buildTree(n - 1);\n    root.right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.cs
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? BuildTree(int n) {\n    if (n == 0) return null;\n    TreeNode root = new(0) {\n        left = BuildTree(n - 1),\n        right = BuildTree(n - 1)\n    };\n    return root;\n}\n
    space_complexity.go
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n int) *treeNode {\n    if n == 0 {\n        return nil\n    }\n    root := newTreeNode(0)\n    root.left = buildTree(n - 1)\n    root.right = buildTree(n - 1)\n    return root\n}\n
    space_complexity.swift
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n: Int) -> TreeNode? {\n    if n == 0 {\n        return nil\n    }\n    let root = TreeNode(x: 0)\n    root.left = buildTree(n: n - 1)\n    root.right = buildTree(n: n - 1)\n    return root\n}\n
    space_complexity.js
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n) {\n    if (n === 0) return null;\n    const root = new TreeNode(0);\n    root.left = buildTree(n - 1);\n    root.right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.ts
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n: number): TreeNode | null {\n    if (n === 0) return null;\n    const root = new TreeNode(0);\n    root.left = buildTree(n - 1);\n    root.right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.dart
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? buildTree(int n) {\n  if (n == 0) return null;\n  TreeNode root = TreeNode(0);\n  root.left = buildTree(n - 1);\n  root.right = buildTree(n - 1);\n  return 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>>> {\n    if n == 0 {return None};\n    let root = TreeNode::new(0);\n    root.borrow_mut().left = build_tree(n - 1);\n    root.borrow_mut().right = build_tree(n - 1);\n    return Some(root);\n}\n
    space_complexity.c
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\n    if (n == 0)\n        return NULL;\n    TreeNode *root = newTreeNode(0);\n    root->left = buildTree(n - 1);\n    root->right = buildTree(n - 1);\n    return 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) {\n    if (n == 0) return null;\n    const root = try mem_allocator.create(inc.TreeNode(i32));\n    root.init(0);\n    root.left = try buildTree(mem_allocator, n - 1);\n    root.right = try buildTree(mem_allocator, n - 1);\n    return 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):\n    a = 2      # 1 ns\n    a = a + 1  # 1 ns\n    a = a * 2  # 10 ns\n    # \u5faa\u73af n \u6b21\n    for _ in range(n):  # 1 ns\n        print(0)        # 5 ns\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        cout << 0 << endl;         // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        System.out.println(0);     // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid Algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        Console.WriteLine(0);      // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n int) {\n    a := 2     // 1 ns\n    a = a + 1  // 1 ns\n    a = a * 2  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for i := 0; i < n; i++ {  // 1 ns\n        fmt.Println(a)        // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n: Int) {\n    var a = 2 // 1 ns\n    a = a + 1 // 1 ns\n    a = a * 2 // 10 ns\n    // \u5faa\u73af n \u6b21\n    for _ in 0 ..< n { // 1 ns\n        print(0) // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n) {\n    var a = 2; // 1 ns\n    a = a + 1; // 1 ns\n    a = a * 2; // 10 ns\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        console.log(0); // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n: number): void {\n    var a: number = 2; // 1 ns\n    a = a + 1; // 1 ns\n    a = a * 2; // 10 ns\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        console.log(0); // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n  int a = 2; // 1 ns\n  a = a + 1; // 1 ns\n  a = a * 2; // 10 ns\n  // \u5faa\u73af n \u6b21\n  for (int i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n    print(0); // 5 ns\n  }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: i32) {\n    let mut a = 2;      // 1 ns\n    a = a + 1;          // 1 ns\n    a = a * 2;          // 10 ns\n    // \u5faa\u73af n \u6b21\n    for _ in 0..n {     // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        println!(\"{}\", 0);  // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {   // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        printf(\"%d\", 0);            // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: usize) void {\n    var a: i32 = 2; // 1 ns\n    a += 1; // 1 ns\n    a *= 2; // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (0..n) |_| { // 1 ns\n        std.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):\n    print(0)\n# \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\ndef algorithm_B(n: int):\n    for _ in range(n):\n        print(0)\n# \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\ndef algorithm_C(n: int):\n    for _ in range(1000000):\n        print(0)\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\n    cout << 0 << endl;\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\n    for (int i = 0; i < n; i++) {\n        cout << 0 << endl;\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        cout << 0 << endl;\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\n    System.out.println(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\n    for (int i = 0; i < n; i++) {\n        System.out.println(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        System.out.println(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmA(int n) {\n    Console.WriteLine(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid AlgorithmB(int n) {\n    for (int i = 0; i < n; i++) {\n        Console.WriteLine(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmC(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        Console.WriteLine(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_A(n int) {\n    fmt.Println(0)\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithm_B(n int) {\n    for i := 0; i < n; i++ {\n        fmt.Println(0)\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_C(n int) {\n    for i := 0; i < 1000000; i++ {\n        fmt.Println(0)\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmA(n: Int) {\n    print(0)\n}\n\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithmB(n: Int) {\n    for _ in 0 ..< n {\n        print(0)\n    }\n}\n\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmC(n: Int) {\n    for _ in 0 ..< 1000000 {\n        print(0)\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n) {\n    console.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n) {\n    for (let i = 0; i < n; i++) {\n        console.log(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n) {\n    for (let i = 0; i < 1000000; i++) {\n        console.log(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n: number): void {\n    console.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n: number): void {\n    for (let i = 0; i < n; i++) {\n        console.log(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n: number): void {\n    for (let i = 0; i < 1000000; i++) {\n        console.log(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmA(int n) {\n  print(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithmB(int n) {\n  for (int i = 0; i < n; i++) {\n    print(0);\n  }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmC(int n) {\n  for (int i = 0; i < 1000000; i++) {\n    print(0);\n  }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_A(n: i32) {\n    println!(\"{}\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfn algorithm_B(n: i32) {\n    for _ in 0..n {\n        println!(\"{}\", 0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_C(n: i32) {\n    for _ in 0..1000000 {\n        println!(\"{}\", 0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\n    printf(\"%d\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\n    for (int i = 0; i < n; i++) {\n        printf(\"%d\", 0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        printf(\"%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;\n    std.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 {\n    for (0..n) |_| {\n        std.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;\n    for (0..1000000) |_| { \n        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):\n    a = 1      # +1\n    a = a + 1  # +1\n    a = a * 2  # +1\n    # \u5faa\u73af n \u6b21\n    for i in range(n):  # +1\n        print(0)        # +1\n
    void algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        cout << 0 << endl;    // +1\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        System.out.println(0);    // +1\n    }\n}\n
    void Algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        Console.WriteLine(0);   // +1\n    }\n}\n
    func algorithm(n int) {\n    a := 1      // +1\n    a = a + 1   // +1\n    a = a * 2   // +1\n    // \u5faa\u73af n \u6b21\n    for i := 0; i < n; i++ {   // +1\n        fmt.Println(a)         // +1\n    }\n}\n
    func algorithm(n: Int) {\n    var a = 1 // +1\n    a = a + 1 // +1\n    a = a * 2 // +1\n    // \u5faa\u73af n \u6b21\n    for _ in 0 ..< n { // +1\n        print(0) // +1\n    }\n}\n
    function algorithm(n) {\n    var a = 1; // +1\n    a += 1; // +1\n    a *= 2; // +1\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        console.log(0); // +1\n    }\n}\n
    function algorithm(n: number): void{\n    var a: number = 1; // +1\n    a += 1; // +1\n    a *= 2; // +1\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        console.log(0); // +1\n    }\n}\n
    void algorithm(int n) {\n  int a = 1; // +1\n  a = a + 1; // +1\n  a = a * 2; // +1\n  // \u5faa\u73af n \u6b21\n  for (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n    print(0); // +1\n  }\n}\n
    fn algorithm(n: i32) {\n    let mut a = 1;   // +1\n    a = a + 1;      // +1\n    a = a * 2;      // +1\n\n    // \u5faa\u73af n \u6b21\n    for _ in 0..n { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        println!(\"{}\", 0); // +1\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        printf(\"%d\", 0);            // +1\n    }\n}  \n
    fn algorithm(n: usize) void {\n    var a: i32 = 1; // +1\n    a += 1; // +1\n    a *= 2; // +1\n    // \u5faa\u73af n \u6b21\n    for (0..n) |_| { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        std.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):\n    a = 1      # +0\uff08\u6280\u5de7 1\uff09\n    a = a + n  # +0\uff08\u6280\u5de7 1\uff09\n    # +n\uff08\u6280\u5de7 2\uff09\n    for i in range(5 * n + 1):\n        print(0)\n    # +n*n\uff08\u6280\u5de7 3\uff09\n    for i in range(2 * n):\n        for j in range(n + 1):\n            print(0)\n
    void algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        cout << 0 << endl;\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            cout << 0 << endl;\n        }\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        System.out.println(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            System.out.println(0);\n        }\n    }\n}\n
    void Algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        Console.WriteLine(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            Console.WriteLine(0);\n        }\n    }\n}\n
    func algorithm(n int) {\n    a := 1     // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for i := 0; i < 5 * n + 1; i++ {\n        fmt.Println(0)\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for i := 0; i < 2 * n; i++ {\n        for j := 0; j < n + 1; j++ {\n            fmt.Println(0)\n        }\n    }\n}\n
    func algorithm(n: Int) {\n    var a = 1 // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for _ in 0 ..< (5 * n + 1) {\n        print(0)\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for _ in 0 ..< (2 * n) {\n        for _ in 0 ..< (n + 1) {\n            print(0)\n        }\n    }\n}\n
    function algorithm(n) {\n    let a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (let i = 0; i < 5 * n + 1; i++) {\n        console.log(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (let i = 0; i < 2 * n; i++) {\n        for (let j = 0; j < n + 1; j++) {\n            console.log(0);\n        }\n    }\n}\n
    function algorithm(n: number): void {\n    let a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (let i = 0; i < 5 * n + 1; i++) {\n        console.log(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (let i = 0; i < 2 * n; i++) {\n        for (let j = 0; j < n + 1; j++) {\n            console.log(0);\n        }\n    }\n}\n
    void algorithm(int n) {\n  int a = 1; // +0\uff08\u6280\u5de7 1\uff09\n  a = a + n; // +0\uff08\u6280\u5de7 1\uff09\n  // +n\uff08\u6280\u5de7 2\uff09\n  for (int i = 0; i < 5 * n + 1; i++) {\n    print(0);\n  }\n  // +n*n\uff08\u6280\u5de7 3\uff09\n  for (int i = 0; i < 2 * n; i++) {\n    for (int j = 0; j < n + 1; j++) {\n      print(0);\n    }\n  }\n}\n
    fn algorithm(n: i32) {\n    let mut a = 1;     // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;        // +0\uff08\u6280\u5de7 1\uff09\n\n    // +n\uff08\u6280\u5de7 2\uff09\n    for i in 0..(5 * n + 1) {\n        println!(\"{}\", 0);\n    }\n\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for i in 0..(2 * n) {\n        for j in 0..(n + 1) {\n            println!(\"{}\", 0);\n        }\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        printf(\"%d\", 0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            printf(\"%d\", 0);\n        }\n    }\n}\n
    fn algorithm(n: usize) void {\n    var a: i32 = 1;     // +0\uff08\u6280\u5de7 1\uff09\n    a = a + @as(i32, @intCast(n));        // +0\uff08\u6280\u5de7 1\uff09\n\n    // +n\uff08\u6280\u5de7 2\uff09\n    for(0..(5 * n + 1)) |_| {\n        std.debug.print(\"{}\\n\", .{0}); \n    }\n\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for(0..(2 * n)) |_| {\n        for(0..(n + 1)) |_| {\n            std.debug.print(\"{}\\n\", .{0}); \n        }\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\"\"\"\n    count = 0\n    size = 100000\n    for _ in range(size):\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n    int count = 0;\n    int size = 100000;\n    for (int i = 0; i < size; i++)\n        count++;\n    return count;\n}\n
    time_complexity.java
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n    int count = 0;\n    int size = 100000;\n    for (int i = 0; i < size; i++)\n        count++;\n    return count;\n}\n
    time_complexity.cs
    /* \u5e38\u6570\u9636 */\nint Constant(int n) {\n    int count = 0;\n    int size = 100000;\n    for (int i = 0; i < size; i++)\n        count++;\n    return count;\n}\n
    time_complexity.go
    /* \u5e38\u6570\u9636 */\nfunc constant(n int) int {\n    count := 0\n    size := 100000\n    for i := 0; i < size; i++ {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5e38\u6570\u9636 */\nfunc constant(n: Int) -> Int {\n    var count = 0\n    let size = 100_000\n    for _ in 0 ..< size {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5e38\u6570\u9636 */\nfunction constant(n) {\n    let count = 0;\n    const size = 100000;\n    for (let i = 0; i < size; i++) count++;\n    return count;\n}\n
    time_complexity.ts
    /* \u5e38\u6570\u9636 */\nfunction constant(n: number): number {\n    let count = 0;\n    const size = 100000;\n    for (let i = 0; i < size; i++) count++;\n    return count;\n}\n
    time_complexity.dart
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n  int count = 0;\n  int size = 100000;\n  for (var i = 0; i < size; i++) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5e38\u6570\u9636 */\nfn constant(n: i32) -> i32 {\n    _ = n;\n    let mut count = 0;\n    let size = 100_000;\n    for _ in 0..size {\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n    int count = 0;\n    int size = 100000;\n    int i = 0;\n    for (int i = 0; i < size; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5e38\u6570\u9636\nfn constant(n: i32) i32 {\n    _ = n;\n    var count: i32 = 0;\n    const size: i32 = 100_000;\n    var i: i32 = 0;\n    while(i<size) : (i += 1) {\n        count += 1;\n    }\n    return 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\"\"\"\n    count = 0\n    for _ in range(n):\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++)\n        count++;\n    return count;\n}\n
    time_complexity.java
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++)\n        count++;\n    return count;\n}\n
    time_complexity.cs
    /* \u7ebf\u6027\u9636 */\nint Linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++)\n        count++;\n    return count;\n}\n
    time_complexity.go
    /* \u7ebf\u6027\u9636 */\nfunc linear(n int) int {\n    count := 0\n    for i := 0; i < n; i++ {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u7ebf\u6027\u9636 */\nfunc linear(n: Int) -> Int {\n    var count = 0\n    for _ in 0 ..< n {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u7ebf\u6027\u9636 */\nfunction linear(n) {\n    let count = 0;\n    for (let i = 0; i < n; i++) count++;\n    return count;\n}\n
    time_complexity.ts
    /* \u7ebf\u6027\u9636 */\nfunction linear(n: number): number {\n    let count = 0;\n    for (let i = 0; i < n; i++) count++;\n    return count;\n}\n
    time_complexity.dart
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n  int count = 0;\n  for (var i = 0; i < n; i++) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u7ebf\u6027\u9636 */\nfn linear(n: i32) -> i32 {\n    let mut count = 0;\n    for _ in 0..n {\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u7ebf\u6027\u9636\nfn linear(n: i32) i32 {\n    var count: i32 = 0;\n    var i: i32 = 0;\n    while (i < n) : (i += 1) {\n        count += 1;\n    }\n    return 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\"\"\"\n    count = 0\n    # \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for num in nums:\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(vector<int> &nums) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (int num : nums) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int[] nums) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (int num : nums) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint ArrayTraversal(int[] nums) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    foreach (int num in nums) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums []int) int {\n    count := 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for range nums {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums: [Int]) -> Int {\n    var count = 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for _ in nums {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums) {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (let i = 0; i < nums.length; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums: number[]): number {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (let i = 0; i < nums.length; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(List<int> nums) {\n  int count = 0;\n  // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n  for (var _num in nums) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfn array_traversal(nums: &[i32]) -> i32 {\n    let mut count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for _ in nums {\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int *nums, int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09\nfn arrayTraversal(nums: []i32) i32 {\n    var count: i32 = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (nums) |_| {\n        count += 1;\n    }\n    return 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\"\"\"\n    count = 0\n    # \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for i in range(n):\n        for j in range(n):\n            count += 1\n    return count\n
    time_complexity.cpp
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u5e73\u65b9\u9636 */\nint Quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u5e73\u65b9\u9636 */\nfunc quadratic(n int) int {\n    count := 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for i := 0; i < n; i++ {\n        for j := 0; j < n; j++ {\n            count++\n        }\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5e73\u65b9\u9636 */\nfunc quadratic(n: Int) -> Int {\n    var count = 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for _ in 0 ..< n {\n        for _ in 0 ..< n {\n            count += 1\n        }\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5e73\u65b9\u9636 */\nfunction quadratic(n) {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u5e73\u65b9\u9636 */\nfunction quadratic(n: number): number {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n  int count = 0;\n  // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n  for (int i = 0; i < n; i++) {\n    for (int j = 0; j < n; j++) {\n      count++;\n    }\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5e73\u65b9\u9636 */\nfn quadratic(n: i32) -> i32 {\n    let mut count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for _ in 0..n {\n        for _ in 0..n {\n            count += 1;\n        }\n    }\n    count\n}\n
    time_complexity.c
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5e73\u65b9\u9636\nfn quadratic(n: i32) i32 {\n    var count: i32 = 0;\n    var i: i32 = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    while (i < n) : (i += 1) {\n        var j: i32 = 0;\n        while (j < n) : (j += 1) {\n            count += 1;\n        }\n    }\n    return 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\"\"\"\n    count = 0  # \u8ba1\u6570\u5668\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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\n        for j in range(i):\n            if nums[j] > nums[j + 1]:\n                # \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                tmp: int = nums[j]\n                nums[j] = nums[j + 1]\n                nums[j + 1] = tmp\n                count += 3  # \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n    return count\n
    time_complexity.cpp
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(vector<int> &nums) {\n    int count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int[] nums) {\n    int count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint BubbleSort(int[] nums) {\n    int count = 0;  // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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 \n        for (int j = 0; j < i; j++) {\n            if (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                count += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums []int) int {\n    count := 0 // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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\n        for j := 0; j < i; j++ {\n            if nums[j] > nums[j+1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                tmp := nums[j]\n                nums[j] = nums[j+1]\n                nums[j+1] = tmp\n                count += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums: inout [Int]) -> Int {\n    var count = 0 // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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 \n        for j in 0 ..< i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j]\n                nums[j] = nums[j + 1]\n                nums[j + 1] = tmp\n                count += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums) {\n    let count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums: number[]): number {\n    let count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(List<int> nums) {\n  int count = 0; // \u8ba1\u6570\u5668\n  // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n  for (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\n    for (var j = 0; j < i; j++) {\n      if (nums[j] > nums[j + 1]) {\n        // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n        int tmp = nums[j];\n        nums[j] = nums[j + 1];\n        nums[j + 1] = tmp;\n        count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n      }\n    }\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfn bubble_sort(nums: &mut [i32]) -> i32 {\n    let mut count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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 \n        for j in 0..i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    count\n}\n
    time_complexity.c
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int *nums, int n) {\n    int count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09\nfn bubbleSort(nums: []i32) i32 {\n    var count: i32 = 0;  // \u8ba1\u6570\u5668 \n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    var i: i32 = @as(i32, @intCast(nums.len)) - 1;\n    while (i > 0) : (i -= 1) {\n        var 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 \n        while (j < i) : (j += 1) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                var tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return 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)\\) \uff1a

    PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
    def exponential(n: int) -> int:\n    \"\"\"\u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\"\"\"\n    count = 0\n    base = 1\n    # \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for _ in range(n):\n        for _ in range(base):\n            count += 1\n        base *= 2\n    # count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count\n
    time_complexity.cpp
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n    int 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)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.java
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n    int 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)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.cs
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Exponential(int n) {\n    int 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)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < bas; j++) {\n            count++;\n        }\n        bas *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.go
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc exponential(n int) int {\n    count, base := 0, 1\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for i := 0; i < n; i++ {\n        for j := 0; j < base; j++ {\n            count++\n        }\n        base *= 2\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count\n}\n
    time_complexity.swift
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc exponential(n: Int) -> Int {\n    var count = 0\n    var base = 1\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for _ in 0 ..< n {\n        for _ in 0 ..< base {\n            count += 1\n        }\n        base *= 2\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count\n}\n
    time_complexity.js
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n) {\n    let count = 0,\n        base = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.ts
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n: number): number {\n    let count = 0,\n        base = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.dart
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n  int 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)\n  for (var i = 0; i < n; i++) {\n    for (var j = 0; j < base; j++) {\n      count++;\n    }\n    base *= 2;\n  }\n  // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n  return count;\n}\n
    time_complexity.rs
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn exponential(n: i32) -> i32 {\n    let mut count = 0;\n    let mut base = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for _ in 0..n {\n        for _ in 0..base {\n            count += 1\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    count\n}\n
    time_complexity.c
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n    int count = 0;\n    int bas = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < bas; j++) {\n            count++;\n        }\n        bas *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.zig
    // \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn exponential(n: i32) i32 {\n    var count: i32 = 0;\n    var bas: i32 = 1;\n    var i: i32 = 0;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    while (i < n) : (i += 1) {\n        var j: i32 = 0;\n        while (j < bas) : (j += 1) {\n            count += 1;\n        }\n        bas *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return 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\"\"\"\n    if n == 1:\n        return 1\n    return 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) {\n    if (n == 1)\n        return 1;\n    return 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) {\n    if (n == 1)\n        return 1;\n    return 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) {\n    if (n == 1) return 1;\n    return 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 {\n    if n == 1 {\n        return 1\n    }\n    return 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 {\n    if n == 1 {\n        return 1\n    }\n    return 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) {\n    if (n === 1) return 1;\n    return 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 {\n    if (n === 1) return 1;\n    return 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) {\n  if (n == 1) return 1;\n  return 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 {\n    if n == 1 {\n        return 1;\n    }\n    exp_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) {\n    if (n == 1)\n        return 1;\n    return 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 {\n    if (n == 1) return 1;\n    return 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\"\"\"\n    count = 0\n    while n > 1:\n        n = n / 2\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n /= 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc logarithmic(n float64) int {\n    count := 0\n    for n > 1 {\n        n = n / 2\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc logarithmic(n: Double) -> Int {\n    var count = 0\n    var n = n\n    while n > 1 {\n        n = n / 2\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n) {\n    let count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n: number): number {\n    let count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(num n) {\n  int count = 0;\n  while (n > 1) {\n    n = n / 2;\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn logarithmic(mut n: f32) -> i32 {\n    let mut count = 0;\n    while n > 1.0 {\n        n = n / 2.0;\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn logarithmic(n: f32) i32 {\n    var count: i32 = 0;\n    var n_var = n;\n    while (n_var > 1)\n    {\n        n_var = n_var / 2;\n        count +=1;\n    }\n    return 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\"\"\"\n    if n <= 1:\n        return 0\n    return log_recur(n / 2) + 1\n
    time_complexity.cpp
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\n    if (n <= 1)\n        return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.java
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\n    if (n <= 1)\n        return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.cs
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint LogRecur(float n) {\n    if (n <= 1) return 0;\n    return LogRecur(n / 2) + 1;\n}\n
    time_complexity.go
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09*/\nfunc logRecur(n float64) int {\n    if n <= 1 {\n        return 0\n    }\n    return logRecur(n/2) + 1\n}\n
    time_complexity.swift
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc logRecur(n: Double) -> Int {\n    if n <= 1 {\n        return 0\n    }\n    return logRecur(n: n / 2) + 1\n}\n
    time_complexity.js
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n) {\n    if (n <= 1) return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.ts
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n: number): number {\n    if (n <= 1) return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.dart
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(num n) {\n  if (n <= 1) return 0;\n  return logRecur(n / 2) + 1;\n}\n
    time_complexity.rs
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn log_recur(n: f32) -> i32 {\n    if n <= 1.0 {\n        return 0;\n    }\n    log_recur(n / 2.0) + 1\n}\n
    time_complexity.c
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\n    if (n <= 1)\n        return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.zig
    // \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn logRecur(n: f32) i32 {\n    if (n <= 1) return 0;\n    return 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\"\"\"\n    if n <= 1:\n        return 1\n    count: int = linear_log_recur(n // 2) + linear_log_recur(n // 2)\n    for _ in range(n):\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\n    if (n <= 1)\n        return 1;\n    int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\n    if (n <= 1)\n        return 1;\n    int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint LinearLogRecur(float n) {\n    if (n <= 1) return 1;\n    int count = LinearLogRecur(n / 2) + LinearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n float64) int {\n    if n <= 1 {\n        return 1\n    }\n    count := linearLogRecur(n/2) + linearLogRecur(n/2)\n    for i := 0.0; i < n; i++ {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n: Double) -> Int {\n    if n <= 1 {\n        return 1\n    }\n    var count = linearLogRecur(n: n / 2) + linearLogRecur(n: n / 2)\n    for _ in stride(from: 0, to: n, by: 1) {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n) {\n    if (n <= 1) return 1;\n    let count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (let i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n: number): number {\n    if (n <= 1) return 1;\n    let count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (let i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(num n) {\n  if (n <= 1) return 1;\n  int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n  for (var i = 0; i < n; i++) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfn linear_log_recur(n: f32) -> i32 {\n    if n <= 1.0 {\n        return 1;\n    }\n    let mut count = linear_log_recur(n / 2.0) + linear_log_recur(n / 2.0);\n    for _ in 0 ..n as i32 {\n        count += 1;\n    }\n    return count\n}\n
    time_complexity.c
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\n    if (n <= 1)\n        return 1;\n    int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u7ebf\u6027\u5bf9\u6570\u9636\nfn linearLogRecur(n: f32) i32 {\n    if (n <= 1) return 1;\n    var count: i32 = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    var i: f32 = 0;\n    while (i < n) : (i += 1) {\n        count += 1;\n    }\n    return 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\"\"\"\n    if n == 0:\n        return 1\n    count = 0\n    # \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for _ in range(n):\n        count += factorial_recur(n - 1)\n    return count\n
    time_complexity.cpp
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n    if (n == 0)\n        return 1;\n    int count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (int i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n    if (n == 0)\n        return 1;\n    int count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (int i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint FactorialRecur(int n) {\n    if (n == 0) return 1;\n    int count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (int i = 0; i < n; i++) {\n        count += FactorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n int) int {\n    if n == 0 {\n        return 1\n    }\n    count := 0\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for i := 0; i < n; i++ {\n        count += factorialRecur(n - 1)\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n: Int) -> Int {\n    if n == 0 {\n        return 1\n    }\n    var count = 0\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for _ in 0 ..< n {\n        count += factorialRecur(n: n - 1)\n    }\n    return count\n}\n
    time_complexity.js
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n) {\n    if (n === 0) return 1;\n    let count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (let i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n: number): number {\n    if (n === 0) return 1;\n    let count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (let i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n  if (n == 0) return 1;\n  int count = 0;\n  // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n  for (var i = 0; i < n; i++) {\n    count += factorialRecur(n - 1);\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn factorial_recur(n: i32) -> i32 {\n    if n == 0 {\n        return 1;\n    }\n    let mut count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for _ in 0..n {\n        count += factorial_recur(n - 1);\n    }\n    count\n}\n
    time_complexity.c
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n    if (n == 0)\n        return 1;\n    int count = 0;\n    for (int i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn factorialRecur(n: i32) i32 {\n    if (n == 0) return 1;\n    var count: i32 = 0;\n    var i: i32 = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    while (i < n) : (i += 1) {\n        count += factorialRecur(n - 1);\n    }\n    return 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\n    nums = [i for i in range(1, n + 1)]\n    # \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    random.shuffle(nums)\n    return nums\n\ndef find_one(nums: list[int]) -> int:\n    \"\"\"\u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\"\"\"\n    for 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)\n        if nums[i] == 1:\n            return i\n    return -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) {\n    vector<int> nums(n);\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u4f7f\u7528\u7cfb\u7edf\u65f6\u95f4\u751f\u6210\u968f\u673a\u79cd\u5b50\n    unsigned seed = chrono::system_clock::now().time_since_epoch().count();\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    shuffle(nums.begin(), nums.end(), default_random_engine(seed));\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(vector<int> &nums) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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) {\n    Integer[] nums = new Integer[n];\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    Collections.shuffle(Arrays.asList(nums));\n    // Integer[] -> int[]\n    int[] res = new int[n];\n    for (int i = 0; i < n; i++) {\n        res[i] = nums[i];\n    }\n    return res;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int[] nums) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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) {\n    int[] nums = new int[n];\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (int i = 0; i < nums.Length; i++) {\n        int index = new Random().Next(i, nums.Length);\n        (nums[i], nums[index]) = (nums[index], nums[i]);\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint FindOne(int[] nums) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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 {\n    nums := make([]int, n)\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for i := 0; i < n; i++ {\n        nums[i] = i + 1\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    rand.Shuffle(len(nums), func(i, j int) {\n        nums[i], nums[j] = nums[j], nums[i]\n    })\n    return nums\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums []int) int {\n    for 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)\n        if nums[i] == 1 {\n            return i\n        }\n    }\n    return -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 }\n    var nums = Array(1 ... n)\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    nums.shuffle()\n    return nums\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums: [Int]) -> Int {\n    for 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)\n        if nums[i] == 1 {\n            return i\n        }\n    }\n    return -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) {\n    const nums = Array(n);\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (let i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (let i = 0; i < n; i++) {\n        const r = Math.floor(Math.random() * (i + 1));\n        const temp = nums[i];\n        nums[i] = nums[r];\n        nums[r] = temp;\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums) {\n    for (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)\n        if (nums[i] === 1) {\n            return i;\n        }\n    }\n    return -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[] {\n    const nums = Array(n);\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (let i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (let i = 0; i < n; i++) {\n        const r = Math.floor(Math.random() * (i + 1));\n        const temp = nums[i];\n        nums[i] = nums[r];\n        nums[r] = temp;\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums: number[]): number {\n    for (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)\n        if (nums[i] === 1) {\n            return i;\n        }\n    }\n    return -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) {\n  final nums = List.filled(n, 0);\n  // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n  for (var i = 0; i < n; i++) {\n    nums[i] = i + 1;\n  }\n  // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n  nums.shuffle();\n\n  return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(List<int> nums) {\n  for (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)\n    if (nums[i] == 1) return i;\n  }\n\n  return -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 }\n    let mut nums = (1..=n).collect::<Vec<i32>>();\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    nums.shuffle(&mut thread_rng());\n    nums\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfn find_one(nums: &[i32]) -> Option<usize> {\n    for 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)\n        if nums[i] == 1 {\n            return Some(i);\n        }\n    }\n    None\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\n    int *nums = (int *)malloc(n * sizeof(int));\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (int i = n - 1; i > 0; i--) {\n        int j = rand() % (i + 1);\n        int temp = nums[i];\n        nums[i] = nums[j];\n        nums[j] = temp;\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int *nums, int n) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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 {\n    var nums: [n]i32 = undefined;\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (&nums, 0..) |*num, i| {\n        num.* = @as(i32, @intCast(i)) + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    const rand = std.crypto.random;\n    rand.shuffle(i32, &nums);\n    return nums;\n}\n\n// \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\nfn findOne(nums: []i32) i32 {\n    for (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)\n        if (num == 1) return @intCast(i);\n    }\n    return -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\\) \u5b57\u8282 = \\(8\\) \u6bd4\u7279 \uff0c\u53ef\u4ee5\u8868\u793a \\(2^{8}\\) \u4e2a\u6570\u5b57\u3002
    • \u6574\u6570\u7c7b\u578b int \u5360\u7528 \\(4\\) \u5b57\u8282 = \\(32\\) \u6bd4\u7279 \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 \u5b57\u8282 \\(-2^7\\) (\\(-128\\)) \\(2^7 - 1\\) (\\(127\\)) \\(0\\) short 2 \u5b57\u8282 \\(-2^{15}\\) \\(2^{15} - 1\\) \\(0\\) int 4 \u5b57\u8282 \\(-2^{31}\\) \\(2^{31} - 1\\) \\(0\\) long 8 \u5b57\u8282 \\(-2^{63}\\) \\(2^{63} - 1\\) \\(0\\) \u6d6e\u70b9\u6570 float 4 \u5b57\u8282 \\(1.175 \\times 10^{-38}\\) \\(3.403 \\times 10^{38}\\) \\(0.0\\text{f}\\) double 8 \u5b57\u8282 \\(2.225 \\times 10^{-308}\\) \\(1.798 \\times 10^{308}\\) \\(0.0\\) \u5b57\u7b26 char 2 \u5b57\u8282 \\(0\\) \\(2^{16} - 1\\) \\(0\\) \u5e03\u5c14 bool 1 \u5b57\u8282 \\(\\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\u90fd\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\u7684\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\u4e5f\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 \u8fd8\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\u300cEASCII\u300d\u5b57\u7b26\u96c6\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\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 \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 \u5b57\u8282\uff1b\u5982\u679c\u6709\u8d85\u51fa BMP \u7684\u5b57\u7b26\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 4 \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\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\u5730\u5740\u7a7a\u95f4\u3001\u5185\u5b58\u7ba1\u7406\u3001\u7f13\u5b58\u673a\u5236\u3001\u865a\u62df\u5185\u5b58\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\u4e5f\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 \u539f\u7801\u3001\u53cd\u7801\u548c\u8865\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-magnitude\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 \u5b57\u8282 \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 \u4f4d\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 \u4f4d \uff0c\u5bf9\u5e94 \\(b_{31}\\) \u3002
    • \u6307\u6570\u4f4d \\(\\mathrm{E}\\) \uff1a\u5360 8 \u4f4d \uff0c\u5bf9\u5e94 \\(b_{30} b_{29} \\ldots b_{23}\\) \u3002
    • \u5206\u6570\u4f4d \\(\\mathrm{N}\\) \uff1a\u5360 23 \u4f4d \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\u4e0a\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 \u5360\u7528\u7684\u7a7a\u95f4\u6bd4 UTF-8 \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\u201c\u54c8\u5e0c\u51b2\u7a81\u201d\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\u4e00\u68f5\u6811\u3002\u56e0\u6b64\uff0c\u54c8\u5e0c\u8868\u53ef\u80fd\u540c\u65f6\u5305\u542b\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff08\u6570\u7ec4\u3001\u94fe\u8868\uff09\u548c\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff08\u6811\uff09\u3002

    char \u7c7b\u578b\u7684\u957f\u5ea6\u662f 1 \u5b57\u8282\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 \u5b57\u8282\u3002

    \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u79f0\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d \u662f\u5426\u6709\u6b67\u4e49\uff1f\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\u65e7\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\u7531\u7c7b\u5185\u90e8\u81ea\u52a8\u5b8c\u6210\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\u540e\u7eed\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\n    if i > j:\n        return -1\n    # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    m = (i + j) // 2\n    if nums[m] < target:\n        # \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j)\n    elif nums[m] > target:\n        # \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1)\n    else:\n        # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m\n\ndef binary_search(nums: list[int], target: int) -> int:\n    \"\"\"\u4e8c\u5206\u67e5\u627e\"\"\"\n    n = len(nums)\n    # \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(vector<int> &nums, int target) {\n    int n = nums.size();\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int[] nums, int target) {\n    int n = nums.length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return DFS(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return DFS(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint BinarySearch(int[] nums, int target) {\n    int n = nums.Length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if i > j {\n        return -1\n    }\n    //    \u8ba1\u7b97\u7d22\u5f15\u4e2d\u70b9\n    m := i + ((j - i) >> 1)\n    //\u5224\u65ad\u4e2d\u70b9\u4e0e\u76ee\u6807\u5143\u7d20\u5927\u5c0f\n    if nums[m] < target {\n        // \u5c0f\u4e8e\u5219\u9012\u5f52\u53f3\u534a\u6570\u7ec4\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return 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)\n        return dfs(nums, target, i, m-1)\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums []int, target int) int {\n    n := len(nums)\n    return 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\n    if i > j {\n        return -1\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    let m = (i + j) / 2\n    if nums[m] < target {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return 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)\n        return 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\n        return m\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums: [Int], target: Int) -> Int {\n    let n = nums.count\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    const m = i + ((j - i) >> 1);\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums, target) {\n    const n = nums.length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    const m = i + ((j - i) >> 1);\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums: number[], target: number): number {\n    const n = nums.length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n  if (i > j) {\n    return -1;\n  }\n  // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n  int m = (i + j) ~/ 2;\n  if (nums[m] < target) {\n    // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n    return dfs(nums, target, m + 1, j);\n  } else if (nums[m] > target) {\n    // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n    return dfs(nums, target, i, m - 1);\n  } else {\n    // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n    return m;\n  }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(List<int> nums, int target) {\n  int n = nums.length;\n  // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n  return 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\n    if i > j { return -1; }\n    let m: i32 = (i + j) / 2;\n    if nums[m as usize] < target {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if nums[m as usize] > target {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfn binary_search(nums: &[i32], target: i32) -> i32 {\n    let n = nums.len() as i32;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    dfs(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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int nums[], int target, int numsSize) {\n    int n = numsSize;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return dfs(nums, target, 0, n - 1);\n}\n
    binary_search_recur.zig
    [class]{}-[func]{dfs}\n\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 \u7684\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\u7ed3\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(\n    preorder: list[int],\n    inorder_map: dict[int, int],\n    i: int,\n    l: int,\n    r: int,\n) -> TreeNode | None:\n    \"\"\"\u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb\"\"\"\n    # \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\n    if r - l < 0:\n        return None\n    # \u521d\u59cb\u5316\u6839\u8282\u70b9\n    root = TreeNode(preorder[i])\n    # \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    m = inorder_map[preorder[i]]\n    # \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorder_map, i + 1, l, m - 1)\n    # \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r)\n    # \u8fd4\u56de\u6839\u8282\u70b9\n    return root\n\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\n    inorder_map = {val: i for i, val in enumerate(inorder)}\n    root = dfs(preorder, inorder_map, 0, 0, len(inorder) - 1)\n    return 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\n    if (r - l < 0)\n        return NULL;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode *root = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap[preorder[i]];\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root->left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    unordered_map<int, int> inorderMap;\n    for (int i = 0; i < inorder.size(); i++) {\n        inorderMap[inorder[i]] = i;\n    }\n    TreeNode *root = dfs(preorder, inorderMap, 0, 0, inorder.size() - 1);\n    return 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\n    if (r - l < 0)\n        return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode root = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap.get(preorder[i]);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    Map<Integer, Integer> inorderMap = new HashMap<>();\n    for (int i = 0; i < inorder.length; i++) {\n        inorderMap.put(inorder[i], i);\n    }\n    TreeNode root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n    return 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\n    if (r - l < 0)\n        return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode root = new(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap[preorder[i]];\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = DFS(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = DFS(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    Dictionary<int, int> inorderMap = [];\n    for (int i = 0; i < inorder.Length; i++) {\n        inorderMap.TryAdd(inorder[i], i);\n    }\n    TreeNode? root = DFS(preorder, inorderMap, 0, 0, inorder.Length - 1);\n    return 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\n    if r-l < 0 {\n        return nil\n    }\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    root := NewTreeNode(preorder[i])\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    m := inorderMap[preorder[i]]\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.Left = dfsBuildTree(preorder, inorderMap, i+1, l, m-1)\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.Right = dfsBuildTree(preorder, inorderMap, i+1+m-l, m+1, r)\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root\n}\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\n    inorderMap := make(map[int]int, len(inorder))\n    for i := 0; i < len(inorder); i++ {\n        inorderMap[inorder[i]] = i\n    }\n\n    root := dfsBuildTree(preorder, inorderMap, 0, 0, len(inorder)-1)\n    return 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\n    if r - l < 0 {\n        return nil\n    }\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    let root = TreeNode(x: preorder[i])\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    let m = inorderMap[preorder[i]]!\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1, l: l, r: m - 1)\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1 + m - l, l: m + 1, r: r)\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root\n}\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\n    let inorderMap = inorder.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }\n    return 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\n    if (r - l < 0) return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    const root = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    const m = inorderMap.get(preorder[i]);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    let inorderMap = new Map();\n    for (let i = 0; i < inorder.length; i++) {\n        inorderMap.set(inorder[i], i);\n    }\n    const root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n    return root;\n}\n
    build_tree.ts
    /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunction dfs(\n    preorder: number[],\n    inorderMap: Map<number, number>,\n    i: number,\n    l: number,\n    r: number\n): TreeNode | null {\n    // \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\n    if (r - l < 0) return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    const root: TreeNode = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    const m = inorderMap.get(preorder[i]);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    let inorderMap = new Map<number, number>();\n    for (let i = 0; i < inorder.length; i++) {\n        inorderMap.set(inorder[i], i);\n    }\n    const root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n    return root;\n}\n
    build_tree.dart
    /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode? dfs(\n  List<int> preorder,\n  Map<int, int> inorderMap,\n  int i,\n  int l,\n  int r,\n) {\n  // \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\n  if (r - l < 0) {\n    return null;\n  }\n  // \u521d\u59cb\u5316\u6839\u8282\u70b9\n  TreeNode? root = TreeNode(preorder[i]);\n  // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n  int m = inorderMap[preorder[i]]!;\n  // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n  root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n  // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n  root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n  // \u8fd4\u56de\u6839\u8282\u70b9\n  return root;\n}\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\n  Map<int, int> inorderMap = {};\n  for (int i = 0; i < inorder.length; i++) {\n    inorderMap[inorder[i]] = i;\n  }\n  TreeNode? root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n  return 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\n    if r - l < 0 { return None; }\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    let root = TreeNode::new(preorder[i as usize]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    let m = inorder_map.get(&preorder[i as usize]).unwrap();\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.borrow_mut().left = dfs(preorder, inorder_map, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.borrow_mut().right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    Some(root)\n}\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\n    let mut inorder_map: HashMap<i32, i32> = HashMap::new();\n    for i in 0..inorder.len() {\n        inorder_map.insert(inorder[i], i as i32);\n    }\n    let root = dfs(preorder, &inorder_map, 0, 0, inorder.len() as i32 - 1);\n    root\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\n    if (r - l < 0)\n        return NULL;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode *root = (TreeNode *)malloc(sizeof(TreeNode));\n    root->val = preorder[i];\n    root->left = NULL;\n    root->right = NULL;\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap[preorder[i]];\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root->left = dfs(preorder, inorderMap, i + 1, l, m - 1, size);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r, size);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    int *inorderMap = (int *)malloc(sizeof(int) * MAX_SIZE);\n    for (int i = 0; i < inorderSize; i++) {\n        inorderMap[inorder[i]] = i;\n    }\n    TreeNode *root = dfs(preorder, inorderMap, 0, 0, inorderSize - 1, inorderSize);\n    free(inorderMap);\n    return root;\n}\n
    build_tree.zig
    [class]{}-[func]{dfs}\n\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\u4e2a\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\u5f97\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\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 \u7684\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 \u7684\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 \u7684\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\u4e00\u4e2a\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\n    pan = src.pop()\n    # \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.append(pan)\n\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\n    if i == 1:\n        move(src, tar)\n        return\n    # \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf)\n    # \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar)\n\ndef solve_hanota(A: list[int], B: list[int], C: list[int]):\n    \"\"\"\u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898\"\"\"\n    n = len(A)\n    # \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    int pan = src.back();\n    src.pop_back();\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push_back(pan);\n}\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\n    if (i == 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(vector<int> &A, vector<int> &B, vector<int> &C) {\n    int n = A.size();\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    Integer pan = src.remove(src.size() - 1);\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.add(pan);\n}\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\n    if (i == 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<Integer> A, List<Integer> B, List<Integer> C) {\n    int n = A.size();\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    int pan = src[^1];\n    src.RemoveAt(src.Count - 1);\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.Add(pan);\n}\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\n    if (i == 1) {\n        Move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    DFS(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    Move(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\n    DFS(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid SolveHanota(List<int> A, List<int> B, List<int> C) {\n    int n = A.Count;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    DFS(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\n    pan := src.Back()\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.PushBack(pan.Value)\n    // \u79fb\u9664 src \u9876\u90e8\u5706\u76d8\n    src.Remove(pan)\n}\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\n    if i == 1 {\n        move(src, tar)\n        return\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfsHanota(i-1, src, tar, buf)\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfsHanota(i-1, buf, src, tar)\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A, B, C *list.List) {\n    n := A.Len()\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfsHanota(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\n    let pan = src.popLast()!\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.append(pan)\n}\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\n    if i == 1 {\n        move(src: &src, tar: &tar)\n        return\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(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\n    move(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\n    dfs(i: i - 1, src: &buf, buf: &src, tar: &tar)\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A: inout [Int], B: inout [Int], C: inout [Int]) {\n    let 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\n    dfs(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\n    const pan = src.pop();\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push(pan);\n}\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\n    if (i === 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A, B, C) {\n    const n = A.length;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    const pan = src.pop();\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push(pan);\n}\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\n    if (i === 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A: number[], B: number[], C: number[]): void {\n    const n = A.length;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n  int pan = src.removeLast();\n  // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n  tar.add(pan);\n}\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\n  if (i == 1) {\n    move(src, tar);\n    return;\n  }\n  // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n  dfs(i - 1, src, tar, buf);\n  // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n  move(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\n  dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<int> A, List<int> B, List<int> C) {\n  int n = A.length;\n  // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n  dfs(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\n    let pan = src.remove(src.len() - 1);\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push(pan);\n}\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\n    if i == 1 {\n        move_pan(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move_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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfn solve_hanota(A: &mut Vec<i32>, B: &mut Vec<i32>, C: &mut Vec<i32>) {\n    let n = A.len() as i32;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    int pan = src[*srcSize - 1];\n    src[*srcSize - 1] = 0;\n    (*srcSize)--;\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar[*tarSize] = pan;\n    (*tarSize)++;\n}\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\n    if (i == 1) {\n        move(src, srcSize, tar, tarSize);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(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\n    move(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\n    dfs(i - 1, buf, bufSize, src, srcSize, tar, tarSize);\n}\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\n    dfs(*ASize, A, ASize, B, BSize, C, CSize);\n}\n
    hanota.zig
    [class]{}-[func]{move}\n\n[class]{}-[func]{dfs}\n\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\"\"\"\n    n = len(cost) - 1\n    if n == 1 or n == 2:\n        return cost[n]\n    # \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp = [0] * (n + 1)\n    # \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[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\n    for i in range(3, n + 1):\n        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\n    return 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) {\n    int n = cost.size() - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    vector<int> dp(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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) {\n    int n = cost.length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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) {\n    int n = cost.Length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = Math.Min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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 {\n    n := len(cost) - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    min := func(a, b int) int {\n        if a < b {\n            return a\n        }\n        return b\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp := make([]int, n+1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1]\n    dp[2] = cost[2]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        dp[i] = min(dp[i-1], dp[i-2]) + cost[i]\n    }\n    return 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 {\n    let n = cost.count - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = Array(repeating: 0, count: n + 1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1]\n    dp[2] = cost[2]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in stride(from: 3, through: n, by: 1) {\n        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\n    }\n    return 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) {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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 {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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) {\n  int n = cost.length - 1;\n  if (n == 1 || n == 2) return cost[n];\n  // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n  List<int> dp = List.filled(n + 1, 0);\n  // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n  dp[1] = cost[1];\n  dp[2] = cost[2];\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n  for (int i = 3; i <= n; i++) {\n    dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n  }\n  return 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 {\n    let n = cost.len() - 1;\n    if n == 1 || n == 2 { return cost[n]; }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    let mut dp = vec![-1; n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in 3..=n {\n        dp[i] = cmp::min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    dp[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) {\n    int n = costSize - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int *dp = calloc(n + 1, sizeof(int));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = myMin(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    int res = dp[n];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = cost.len - 1;\n    if (n == 1 or n == 2) {\n        return cost[n];\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = [_]i32{-1} ** (n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        dp[i] = @min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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\"\"\"\n    n = len(cost) - 1\n    if n == 1 or n == 2:\n        return cost[n]\n    a, b = cost[1], cost[2]\n    for i in range(3, n + 1):\n        a, b = b, min(a, b) + cost[i]\n    return 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) {\n    int n = cost.size() - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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) {\n    int n = cost.length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = Math.min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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) {\n    int n = cost.Length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = Math.Min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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 {\n    n := len(cost) - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    min := func(a, b int) int {\n        if a < b {\n            return a\n        }\n        return b\n    }\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    a, 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\n    for i := 3; i <= n; i++ {\n        tmp := b\n        b = min(a, tmp) + cost[i]\n        a = tmp\n    }\n    return 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 {\n    let n = cost.count - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    var (a, b) = (cost[1], cost[2])\n    for i in stride(from: 3, through: n, by: 1) {\n        (a, b) = (b, min(a, b) + cost[i])\n    }\n    return 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) {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    let a = cost[1],\n        b = cost[2];\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = Math.min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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 {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    let a = cost[1],\n        b = cost[2];\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = Math.min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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) {\n  int n = cost.length - 1;\n  if (n == 1 || n == 2) return cost[n];\n  int a = cost[1], b = cost[2];\n  for (int i = 3; i <= n; i++) {\n    int tmp = b;\n    b = min(a, tmp) + cost[i];\n    a = tmp;\n  }\n  return 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 {\n    let n = cost.len() - 1;\n    if n == 1 || n == 2 { return cost[n] };\n    let (mut a, mut b) = (cost[1], cost[2]);\n    for i in 3..=n {\n        let tmp = b;\n        b = cmp::min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    b\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) {\n    int n = costSize - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = myMin(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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 {\n    var n = cost.len - 1;\n    if (n == 1 or n == 2) {\n        return cost[n];\n    }\n    var a = cost[1];\n    var b = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        var tmp = b;\n        b = @min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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\u4e00\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\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\"\"\"\n    if n == 1 or n == 2:\n        return 1\n    # \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp = [[0] * 3 for _ in range(n + 1)]\n    # \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1], dp[1][2] = 1, 0\n    dp[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\n    for i in range(3, n + 1):\n        dp[i][1] = dp[i - 1][2]\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2]\n    return 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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    vector<vector<int>> dp(n + 1, vector<int>(3, 0));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[][] dp = new int[n + 1][3];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[,] dp = new int[n + 1, 3];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1, 1] = 1;\n    dp[1, 2] = 0;\n    dp[2, 1] = 0;\n    dp[2, 2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i, 1] = dp[i - 1, 2];\n        dp[i, 2] = dp[i - 2, 1] + dp[i - 2, 2];\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return 1\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp := make([][3]int, n+1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1\n    dp[1][2] = 0\n    dp[2][1] = 0\n    dp[2][2] = 1\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        dp[i][1] = dp[i-1][2]\n        dp[i][2] = dp[i-2][1] + dp[i-2][2]\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return 1\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var 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\n    dp[1][1] = 1\n    dp[1][2] = 0\n    dp[2][1] = 0\n    dp[2][2] = 1\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in stride(from: 3, through: n, by: 1) {\n        dp[i][1] = dp[i - 1][2]\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2]\n    }\n    return 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) {\n    if (n === 1 || n === 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const 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\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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 {\n    if (n === 1 || n === 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = Array.from({ length: n + 1 }, () => new Array(3));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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) {\n  if (n == 1 || n == 2) {\n    return 1;\n  }\n  // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n  List<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\n  dp[1][1] = 1;\n  dp[1][2] = 0;\n  dp[2][1] = 0;\n  dp[2][2] = 1;\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n  for (int i = 3; i <= n; i++) {\n    dp[i][1] = dp[i - 1][2];\n    dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n  }\n  return 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 {\n    if n == 1 || n == 2 { return 1 };\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    let mut dp = vec![vec![-1; 3]; n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in 3..=n {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    dp[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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(3, sizeof(int));\n    }\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    int res = dp[n][1] + dp[n][2];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    free(dp);\n    return 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 {\n    if (n == 1 or n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = [_][3]i32{ [_]i32{ -1, -1, -1 } } ** (n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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\u201d\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\n    if i == 0 and j == 0:\n        return grid[0][0]\n    # \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 or j < 0:\n        return inf\n    # \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    up = min_path_sum_dfs(grid, i - 1, j)\n    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\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = minPathSumDFS(grid, i - 1, j);\n    int left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = minPathSumDFS(grid, i - 1, j);\n    int left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = MinPathSumDFS(grid, i - 1, j);\n    int left = MinPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if i == 0 && j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return 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\n    up := minPathSumDFS(grid, i-1, j)\n    left := minPathSumDFS(grid, i, j-1)\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if i == 0, j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return .max\n    }\n    // \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    let up = minPathSumDFS(grid: grid, i: i - 1, j: j)\n    let 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\n    return 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\n    if (i === 0 && j === 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFS(grid, i - 1, j);\n    const left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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(\n    grid: Array<Array<number>>,\n    i: number,\n    j: number\n): number {\n    // \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\n    if (i === 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFS(grid, i - 1, j);\n    const left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n  if (i == 0 && j == 0) {\n    return grid[0][0];\n  }\n  // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n  if (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\n    return 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\n  int up = minPathSumDFS(grid, i - 1, j);\n  int left = minPathSumDFS(grid, i, j - 1);\n  // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n  return 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\n    if i == 0 && j == 0 {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return 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\n    let up = min_path_sum_dfs(grid, i - 1, j);\n    let 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\n    std::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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = minPathSumDFS(grid, i - 1, j);\n    int left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if (i == 0 and j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 or j < 0) {\n        return 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\n    var up = minPathSumDFS(grid, i - 1, j);\n    var left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return @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(\n    grid: 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\n    if i == 0 and j == 0:\n        return grid[0][0]\n    # \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 or j < 0:\n        return inf\n    # \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][j] != -1:\n        return mem[i][j]\n    # \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    up = min_path_sum_dfs_mem(grid, mem, i - 1, j)\n    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\n    mem[i][j] = min(left, up) + grid[i][j]\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return INT_MAX;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = minPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = min(left, up) != INT_MAX ? min(left, up) + grid[i][j] : INT_MAX;\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Integer.MAX_VALUE;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = minPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = Math.min(left, up) + grid[i][j];\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return int.MaxValue;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = MinPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = Math.Min(left, up) + grid[i][j];\n    return 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\n    if i == 0 && j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return math.MaxInt\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][j] != -1 {\n        return mem[i][j]\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    up := minPathSumDFSMem(grid, mem, i-1, j)\n    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\n    mem[i][j] = int(math.Min(float64(left), float64(up))) + grid[i][j]\n    return 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\n    if i == 0, j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return .max\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][j] != -1 {\n        return mem[i][j]\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    let up = minPathSumDFSMem(grid: grid, mem: &mem, i: i - 1, j: j)\n    let 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\n    mem[i][j] = min(left, up) + grid[i][j]\n    return 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\n    if (i === 0 && j === 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] !== -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFSMem(grid, mem, i - 1, j);\n    const 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\n    mem[i][j] = Math.min(left, up) + grid[i][j];\n    return mem[i][j];\n}\n
    min_path_sum.ts
    /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction minPathSumDFSMem(\n    grid: Array<Array<number>>,\n    mem: Array<Array<number>>,\n    i: number,\n    j: number\n): number {\n    // \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\n    if (i === 0 && j === 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFSMem(grid, mem, i - 1, j);\n    const 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\n    mem[i][j] = Math.min(left, up) + grid[i][j];\n    return 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\n  if (i == 0 && j == 0) {\n    return grid[0][0];\n  }\n  // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n  if (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\n    return BigInt.from(2).pow(31).toInt();\n  }\n  // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n  if (mem[i][j] != -1) {\n    return mem[i][j];\n  }\n  // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n  int up = minPathSumDFSMem(grid, mem, i - 1, j);\n  int 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\n  mem[i][j] = min(left, up) + grid[i][j];\n  return 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\n    if i == 0 && j == 0 {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return i32::MAX;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i as usize][j as usize] != -1 {\n        return mem[i as usize][j as usize];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    let up = min_path_sum_dfs_mem(grid, mem, i - 1, j);\n    let 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\n    mem[i as usize][j as usize] = std::cmp::min(left, up) + grid[i as usize][j as usize];\n    mem[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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return INT_MAX;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = minPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = myMin(left, up) != INT_MAX ? myMin(left, up) + grid[i][j] : INT_MAX;\n    return 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\n    if (i == 0 and j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 or j < 0) {\n        return std.math.maxInt(i32);\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] != -1) {\n        return 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\n    var up = minPathSumDFSMem(grid, mem, i - 1, j);\n    var 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\n    mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] = @min(left, up) + grid[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n    return 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\"\"\"\n    n, m = len(grid), len(grid[0])\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * m for _ in range(n)]\n    dp[0][0] = grid[0][0]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in range(1, m):\n        dp[0][j] = dp[0][j - 1] + grid[0][j]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i in range(1, n):\n        dp[i][0] = dp[i - 1][0] + grid[i][0]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in range(1, n):\n        for j in range(1, m):\n            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\n    return 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) {\n    int n = grid.size(), m = grid[0].size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n, vector<int>(m));\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.length, m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n][m];\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.Length, m = grid[0].Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n, m];\n    dp[0, 0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0, j] = dp[0, j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i, 0] = dp[i - 1, 0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i, j] = Math.Min(dp[i, j - 1], dp[i - 1, j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    n, m := len(grid), len(grid[0])\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n)\n    for i := 0; i < n; i++ {\n        dp[i] = make([]int, m)\n    }\n    dp[0][0] = grid[0][0]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j := 1; j < m; j++ {\n        dp[0][j] = dp[0][j-1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i := 1; i < n; i++ {\n        dp[i][0] = dp[i-1][0] + grid[i][0]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i < n; i++ {\n        for j := 1; j < m; j++ {\n            dp[i][j] = int(math.Min(float64(dp[i][j-1]), float64(dp[i-1][j]))) + grid[i][j]\n        }\n    }\n    return 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 {\n    let n = grid.count\n    let m = grid[0].count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: m), count: n)\n    dp[0][0] = grid[0][0]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in stride(from: 1, to: m, by: 1) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i in stride(from: 1, to: n, by: 1) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in stride(from: 1, to: n, by: 1) {\n        for j in stride(from: 1, to: m, by: 1) {\n            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\n        }\n    }\n    return dp[n - 1][m - 1]\n}\n
    min_path_sum.js
    /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDP(grid) {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n }, () =>\n        Array.from({ length: m }, () => 0)\n    );\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (let i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i < n; i++) {\n        for (let j = 1; j < m; j++) {\n            dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n }, () =>\n        Array.from({ length: m }, () => 0)\n    );\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (let i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i < n; i++) {\n        for (let j: number = 1; j < m; j++) {\n            dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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) {\n  int n = grid.length, m = grid[0].length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n, (i) => List.filled(m, 0));\n  dp[0][0] = grid[0][0];\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n  for (int j = 1; j < m; j++) {\n    dp[0][j] = dp[0][j - 1] + grid[0][j];\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n  for (int i = 1; i < n; i++) {\n    dp[i][0] = dp[i - 1][0] + grid[i][0];\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n  for (int i = 1; i < n; i++) {\n    for (int j = 1; j < m; j++) {\n      dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n    }\n  }\n  return 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 {\n    let (n, m) = (grid.len(), grid[0].len());\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; m]; n];\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in 1..m {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i in 1..n {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in 1..n {\n        for j in 1..m {\n            dp[i][j] = std::cmp::min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    dp[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\n    int **dp = malloc(n * sizeof(int *));\n    for (int i = 0; i < n; i++) {\n        dp[i] = calloc(m, sizeof(int));\n    }\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i][j] = myMin(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    int res = dp[n - 1][m - 1];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i < n; i++) {\n        free(dp[i]);\n    }\n    return res;\n}\n
    min_path_sum.zig
    // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212\nfn minPathSumDP(comptime grid: anytype) i32 {\n    comptime var n = grid.len;\n    comptime var m = grid[0].len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][m]i32{[_]i32{0} ** m} ** n;\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (1..m) |j| {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (1..n) |i| {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (1..n) |i| {\n        for (1..m) |j| {\n            dp[i][j] = @min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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\"\"\"\n    n, m = len(grid), len(grid[0])\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * m\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0]\n    for j in range(1, m):\n        dp[j] = dp[j - 1] + grid[0][j]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in range(1, n):\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0]\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in range(1, m):\n            dp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\n    return 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) {\n    int n = grid.size(), m = grid[0].size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(m);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.length, m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[m];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.Length, m = grid[0].Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[m];\n    dp[0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = Math.Min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    n, m := len(grid), len(grid[0])\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, m)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0]\n    for j := 1; j < m; j++ {\n        dp[j] = dp[j-1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i < n; i++ {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0]\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j := 1; j < m; j++ {\n            dp[j] = int(math.Min(float64(dp[j-1]), float64(dp[j]))) + grid[i][j]\n        }\n    }\n    return 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 {\n    let n = grid.count\n    let m = grid[0].count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: m)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0]\n    for j in stride(from: 1, to: m, by: 1) {\n        dp[j] = dp[j - 1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in stride(from: 1, to: n, by: 1) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0]\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in stride(from: 1, to: m, by: 1) {\n            dp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\n        }\n    }\n    return 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) {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = new Array(m);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (let j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j < m; j++) {\n            dp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = new Array(m);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (let j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j < m; j++) {\n            dp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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) {\n  int n = grid.length, m = grid[0].length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(m, 0);\n  dp[0] = grid[0][0];\n  for (int j = 1; j < m; j++) {\n    dp[j] = dp[j - 1] + grid[0][j];\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n  for (int i = 1; i < n; i++) {\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    dp[0] = dp[0] + grid[i][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n    for (int j = 1; j < m; j++) {\n      dp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n    }\n  }\n  return 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 {\n    let (n, m) = (grid.len(), grid[0].len());\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; m];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for j in 1..m {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in 1..n {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in 1..m {\n            dp[j] = std::cmp::min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    dp[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\n    int *dp = calloc(m, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = myMin(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    int res = dp[m - 1];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = grid.len;\n    comptime var m = grid[0].len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** m;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (1..m) |j| {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (1..n) |i| {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        for (1..m) |j| {\n            dp[j] = @min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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\"\"\"\n    n, m = len(s), len(t)\n    dp = [[0] * (m + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i in range(1, n + 1):\n        dp[i][0] = i\n    for j in range(1, m + 1):\n        dp[0][j] = j\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in range(1, n + 1):\n        for j in range(1, m + 1):\n            if s[i - 1] == t[j - 1]:\n                # \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1\n    return dp[n][m]\n
    edit_distance.cpp
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(string s, string t) {\n    int n = s.length(), m = t.length();\n    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.java
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\n    int n = s.length(), m = t.length();\n    int[][] dp = new int[n + 1][m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (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\n                dp[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\n                dp[i][j] = Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.cs
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint EditDistanceDP(string s, string t) {\n    int n = s.Length, m = t.Length;\n    int[,] dp = new int[n + 1, m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i, 0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0, j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i, j] = Math.Min(Math.Min(dp[i, j - 1], dp[i - 1, j]), dp[i - 1, j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n, m];\n}\n
    edit_distance.go
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s string, t string) int {\n    n := len(s)\n    m := len(t)\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, m+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i := 1; i <= n; i++ {\n        dp[i][0] = i\n    }\n    for j := 1; j <= m; j++ {\n        dp[0][j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i <= n; i++ {\n        for j := 1; j <= m; j++ {\n            if s[i-1] == t[j-1] {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = MinInt(MinInt(dp[i][j-1], dp[i-1][j]), dp[i-1][j-1]) + 1\n            }\n        }\n    }\n    return dp[n][m]\n}\n
    edit_distance.swift
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s: String, t: String) -> Int {\n    let n = s.utf8CString.count\n    let m = t.utf8CString.count\n    var dp = Array(repeating: Array(repeating: 0, count: m + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i in stride(from: 1, through: n, by: 1) {\n        dp[i][0] = i\n    }\n    for j in stride(from: 1, through: m, by: 1) {\n        dp[0][j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in stride(from: 1, through: n, by: 1) {\n        for j in stride(from: 1, through: m, by: 1) {\n            if 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\n                dp[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\n                dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1\n            }\n        }\n    }\n    return dp[n][m]\n}\n
    edit_distance.js
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s, t) {\n    const n = s.length,\n        m = t.length;\n    const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (let j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let j = 1; j <= m; j++) {\n            if (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\n                dp[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\n                dp[i][j] =\n                    Math.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.ts
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s: string, t: string): number {\n    const n = s.length,\n        m = t.length;\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: m + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (let j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let j = 1; j <= m; j++) {\n            if (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\n                dp[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\n                dp[i][j] =\n                    Math.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.dart
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\n  int n = s.length, m = t.length;\n  List<List<int>> dp = List.generate(n + 1, (_) => List.filled(m + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n  for (int i = 1; i <= n; i++) {\n    dp[i][0] = i;\n  }\n  for (int j = 1; j <= m; j++) {\n    dp[0][j] = j;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n  for (int i = 1; i <= n; i++) {\n    for (int j = 1; j <= m; j++) {\n      if (s[i - 1] == t[j - 1]) {\n        // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n        dp[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\n        dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n      }\n    }\n  }\n  return 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 {\n    let (n, m) = (s.len(), t.len());\n    let mut dp = vec![vec![0; m + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i in 1..= n {\n        dp[i][0] = i as i32;\n    }\n    for j in 1..m {\n        dp[0][j] = j as i32;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in 1..=n {\n        for j in 1..=m {\n            if 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\n                dp[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\n                dp[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    }\n    dp[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) {\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(m + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = myMin(myMin(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    int res = dp[n][m];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    return 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 {\n    comptime var n = s.len;\n    comptime var m = t.len;\n    var dp = [_][m + 1]i32{[_]i32{0} ** (m + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (1..n + 1) |i| {\n        dp[i][0] = @intCast(i);\n    }\n    for (1..m + 1) |j| {\n        dp[0][j] = @intCast(j);\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (1..n + 1) |i| {\n        for (1..m + 1) |j| {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = @min(@min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return 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\"\"\"\n    n, m = len(s), len(t)\n    dp = [0] * (m + 1)\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in range(1, m + 1):\n        dp[j] = j\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in range(1, n + 1):\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        leftup = dp[0]  # \u6682\u5b58 dp[i-1, j-1]\n        dp[0] += 1\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in range(1, m + 1):\n            temp = dp[j]\n            if s[i - 1] == t[j - 1]:\n                # \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = min(dp[j - 1], dp[j], leftup) + 1\n            leftup = temp  # \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n    return 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) {\n    int n = s.length(), m = t.length();\n    vector<int> dp(m + 1, 0);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n    int n = s.length(), m = t.length();\n    int[] dp = new int[m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (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\n                dp[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\n                dp[j] = Math.min(Math.min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n    int n = s.Length, m = t.Length;\n    int[] dp = new int[m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = Math.Min(Math.Min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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 {\n    n := len(s)\n    m := len(t)\n    dp := make([]int, m+1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j := 1; j <= m; j++ {\n        dp[j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i := 1; i <= n; i++ {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        leftUp := dp[0] // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j := 1; j <= m; j++ {\n            temp := dp[j]\n            if s[i-1] == t[j-1] {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = MinInt(MinInt(dp[j-1], dp[j]), leftUp) + 1\n            }\n            leftUp = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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 {\n    let n = s.utf8CString.count\n    let m = t.utf8CString.count\n    var dp = Array(repeating: 0, count: m + 1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in stride(from: 1, through: m, by: 1) {\n        dp[j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in stride(from: 1, through: n, by: 1) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        var leftup = dp[0] // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in stride(from: 1, through: m, by: 1) {\n            let temp = dp[j]\n            if 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\n                dp[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\n                dp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1\n            }\n            leftup = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n    const n = s.length,\n        m = t.length;\n    const dp = new Array(m + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        let leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j <= m; j++) {\n            const temp = dp[j];\n            if (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\n                dp[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\n                dp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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 {\n    const n = s.length,\n        m = t.length;\n    const dp = new Array(m + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        let leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j <= m; j++) {\n            const temp = dp[j];\n            if (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\n                dp[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\n                dp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n  int n = s.length, m = t.length;\n  List<int> dp = List.filled(m + 1, 0);\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n  for (int j = 1; j <= m; j++) {\n    dp[j] = j;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n  for (int i = 1; i <= n; i++) {\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n    dp[0] = i;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n    for (int j = 1; j <= m; j++) {\n      int temp = dp[j];\n      if (s[i - 1] == t[j - 1]) {\n        // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n        dp[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\n        dp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n      }\n      leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n    }\n  }\n  return 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 {\n    let (n, m) = (s.len(), t.len());\n    let mut dp = vec![0; m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in 1..m {\n        dp[j] = j as i32;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in 1..=n {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        let mut leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i as i32;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in 1..=m {\n            let temp = dp[j];\n            if 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\n                dp[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\n                dp[j] = std::cmp::min(std::cmp::min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    dp[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) {\n    int *dp = calloc(m + 1, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = myMin(myMin(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    int res = dp[m];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = s.len;\n    comptime var m = t.len;\n    var dp = [_]i32{0} ** (m + 1);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (1..m + 1) |j| {\n        dp[j] = @intCast(j);\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (1..n + 1) |i| {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        var leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = @intCast(i);\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (1..m + 1) |j| {\n            var temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = @min(@min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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\n    if state == n:\n        res[0] += 1\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices:\n        # \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state + choice > n:\n            continue\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res)\n        # \u56de\u9000\n\ndef climbing_stairs_backtrack(n: int) -> int:\n    \"\"\"\u722c\u697c\u68af\uff1a\u56de\u6eaf\"\"\"\n    choices = [1, 2]  # \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    state = 0  # \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    res = [0]  # \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res)\n    return 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\n    if (state == n)\n        res[0]++;\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (auto &choice : choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n    vector<int> choices = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0;                // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    vector<int> res = {0};        // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return 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\n    if (state == n)\n        res.set(0, res.get(0) + 1);\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (Integer choice : choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n    List<Integer> choices = Arrays.asList(1, 2); // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    List<Integer> res = new ArrayList<>();\n    res.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return 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\n    if (state == n)\n        res[0]++;\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    foreach (int choice in choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        Backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint ClimbingStairsBacktrack(int n) {\n    List<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    List<int> res = [0]; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    Backtrack(choices, state, n, res);\n    return 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\n    if state == n {\n        res[0] = res[0] + 1\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for _, choice := range choices {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state+choice > n {\n            continue\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state+choice, n, res)\n        // \u56de\u9000\n    }\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\n    choices := []int{1, 2}\n    // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    state := 0\n    res := make([]int, 1)\n    // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    res[0] = 0\n    backtrack(choices, state, n, res)\n    return 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\n    if state == n {\n        res[0] += 1\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state + choice > n {\n            continue\n        }\n        backtrack(choices: choices, state: state + choice, n: n, res: &res)\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunc climbingStairsBacktrack(n: Int) -> Int {\n    let choices = [1, 2] // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    let state = 0 // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    var res: [Int] = []\n    res.append(0) // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices: choices, state: state, n: n, res: &res)\n    return 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\n    if (state === n) res.set(0, res.get(0) + 1);\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n) continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n) {\n    const choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    const state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    const res = new Map();\n    res.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return res.get(0);\n}\n
    climbing_stairs_backtrack.ts
    /* \u56de\u6eaf */\nfunction backtrack(\n    choices: number[],\n    state: number,\n    n: number,\n    res: Map<0, any>\n): void {\n    // \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\n    if (state === n) res.set(0, res.get(0) + 1);\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n) continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n: number): number {\n    const choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    const state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    const res = new Map();\n    res.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return 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\n  if (state == n) {\n    res[0]++;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (int choice in choices) {\n    // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n    if (state + choice > n) continue;\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n    backtrack(choices, state + choice, n, res);\n    // \u56de\u9000\n  }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n  List<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n  int state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n  List<int> res = [];\n  res.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n  backtrack(choices, state, n, res);\n  return 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\n    if state == n { res[0] = res[0] + 1; }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for &choice in choices {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state + choice > n { continue; }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfn climbing_stairs_backtrack(n: usize) -> i32 {\n    let choices = vec![ 1, 2 ]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    let state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    let mut res = Vec::new();\n    res.push(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(&choices, state, n as i32, &mut res);\n    res[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\n    if (state == n)\n        res[0]++;\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < len; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res, len);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n    int choices[2] = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0;           // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    int *res = (int *)malloc(sizeof(int));\n    *res = 0; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    int len = sizeof(choices) / sizeof(int);\n    backtrack(choices, state, n, res, len);\n    int result = *res;\n    free(res);\n    return 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\n    if (state == n) {\n        res.items[0] = res.items[0] + 1;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (choices) |choice| {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n// \u722c\u697c\u68af\uff1a\u56de\u6eaf\nfn climbingStairsBacktrack(n: usize) !i32 {\n    var choices = [_]i32{ 1, 2 }; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    var state: i32 = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    var res = std.ArrayList(i32).init(std.heap.page_allocator);\n    defer res.deinit();\n    try res.append(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(&choices, state, @intCast(n), res);\n    return 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\n    if i == 1 or i == 2:\n        return i\n    # dp[i] = dp[i-1] + dp[i-2]\n    count = dfs(i - 1) + dfs(i - 2)\n    return count\n\ndef climbing_stairs_dfs(n: int) -> int:\n    \"\"\"\u722c\u697c\u68af\uff1a\u641c\u7d22\"\"\"\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = DFS(i - 1) + DFS(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint ClimbingStairsDFS(int n) {\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    count := dfs(i-1) + dfs(i-2)\n    return count\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n int) int {\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i: i - 1) + dfs(i: i - 2)\n    return count\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n: Int) -> Int {\n    dfs(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\n    if (i === 1 || i === 2) return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n) {\n    return 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\n    if (i === 1 || i === 2) return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n: number): number {\n    return 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\n  if (i == 1 || i == 2) return i;\n  // dp[i] = dp[i-1] + dp[i-2]\n  int count = dfs(i - 1) + dfs(i - 2);\n  return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n  return 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\n    if i == 1 || i == 2 { return i as i32; }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i - 1) + dfs(i - 2);\n    count\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfn climbing_stairs_dfs(n: usize) -> i32 {\n    dfs(n) \n}\n
    climbing_stairs_dfs.c
    /* \u641c\u7d22 */\nint dfs(int i) {\n    // \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n    return 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\n    if (i == 1 or i == 2) {\n        return @intCast(i);\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    var count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n// \u722c\u697c\u68af\uff1a\u641c\u7d22\nfn climbingStairsDFS(comptime n: usize) i32 {\n    return 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\u5b50\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\n    if i == 1 or i == 2:\n        return i\n    # \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1:\n        return mem[i]\n    # dp[i] = dp[i-1] + dp[i-2]\n    count = dfs(i - 1, mem) + dfs(i - 2, mem)\n    # \u8bb0\u5f55 dp[i]\n    mem[i] = count\n    return count\n\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\n    mem = [-1] * (n + 1)\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    vector<int> mem(n + 1, -1);\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    int[] mem = new int[n + 1];\n    Arrays.fill(mem, -1);\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = DFS(i - 1, mem) + DFS(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    int[] mem = new int[n + 1];\n    Array.Fill(mem, -1);\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1 {\n        return mem[i]\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    count := dfsMem(i-1, mem) + dfsMem(i-2, mem)\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count\n    return count\n}\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\n    mem := make([]int, n+1)\n    for i := range mem {\n        mem[i] = -1\n    }\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1 {\n        return mem[i]\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i: i - 1, mem: &mem) + dfs(i: i - 2, mem: &mem)\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count\n    return count\n}\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\n    var mem = Array(repeating: -1, count: n + 1)\n    return 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\n    if (i === 1 || i === 2) return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1) return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    const mem = new Array(n + 1).fill(-1);\n    return 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\n    if (i === 1 || i === 2) return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1) return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    const mem = new Array(n + 1).fill(-1);\n    return 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\n  if (i == 1 || i == 2) return i;\n  // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n  if (mem[i] != -1) return mem[i];\n  // dp[i] = dp[i-1] + dp[i-2]\n  int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n  // \u8bb0\u5f55 dp[i]\n  mem[i] = count;\n  return count;\n}\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\n  List<int> mem = List.filled(n + 1, -1);\n  return 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\n    if i == 1 || i == 2 { return i as i32; }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1 { return mem[i]; }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    count\n}\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\n    let mut mem = vec![-1; n + 1];\n    dfs(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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    int *mem = (int *)malloc((n + 1) * sizeof(int));\n    for (int i = 0; i <= n; i++) {\n        mem[i] = -1;\n    }\n    int result = dfs(n, mem);\n    free(mem);\n    return 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\n    if (i == 1 or i == 2) {\n        return @intCast(i);\n    }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1) {\n        return mem[i];\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    var count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    var mem = [_]i32{ -1 } ** (n + 1);\n    return 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\"\"\"\n    if n == 1 or n == 2:\n        return n\n    # \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp = [0] * (n + 1)\n    # \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[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\n    for i in range(3, n + 1):\n        dp[i] = dp[i - 1] + dp[i - 2]\n    return dp[n]\n
    climbing_stairs_dp.cpp
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    vector<int> dp(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.java
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.cs
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.go
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n int) int {\n    if n == 1 || n == 2 {\n        return n\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp := make([]int, n+1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1\n    dp[2] = 2\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        dp[i] = dp[i-1] + dp[i-2]\n    }\n    return dp[n]\n}\n
    climbing_stairs_dp.swift
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n: Int) -> Int {\n    if n == 1 || n == 2 {\n        return n\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = Array(repeating: 0, count: n + 1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1\n    dp[2] = 2\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in stride(from: 3, through: n, by: 1) {\n        dp[i] = dp[i - 1] + dp[i - 2]\n    }\n    return dp[n]\n}\n
    climbing_stairs_dp.js
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n) {\n    if (n === 1 || n === 2) return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1).fill(-1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.ts
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n: number): number {\n    if (n === 1 || n === 2) return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1).fill(-1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.dart
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n  if (n == 1 || n == 2) return n;\n  // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n  List<int> dp = List.filled(n + 1, 0);\n  // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n  dp[1] = 1;\n  dp[2] = 2;\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n  for (int i = 3; i <= n; i++) {\n    dp[i] = dp[i - 1] + dp[i - 2];\n  }\n  return 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\n    if n == 1 || n == 2 { return n as i32; }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    let mut dp = vec![-1; n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in 3..=n {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    dp[n]\n}\n
    climbing_stairs_dp.c
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int *dp = (int *)malloc((n + 1) * sizeof(int));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    int result = dp[n];\n    free(dp);\n    return 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\n    if (n == 1 or n == 2) {\n        return @intCast(n);\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = [_]i32{-1} ** (n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return 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\"\"\"\n    if n == 1 or n == 2:\n        return n\n    a, b = 1, 2\n    for _ in range(3, n + 1):\n        a, b = b, a + b\n    return b\n
    climbing_stairs_dp.cpp
    /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return n\n    }\n    a, b := 1, 2\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        a, b = b, a+b\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return n\n    }\n    var a = 1\n    var b = 2\n    for _ in stride(from: 3, through: n, by: 1) {\n        (a, b) = (b, a + b)\n    }\n    return b\n}\n
    climbing_stairs_dp.js
    /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDPComp(n) {\n    if (n === 1 || n === 2) return n;\n    let a = 1,\n        b = 2;\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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 {\n    if (n === 1 || n === 2) return n;\n    let a = 1,\n        b = 2;\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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) {\n  if (n == 1 || n == 2) return n;\n  int a = 1, b = 2;\n  for (int i = 3; i <= n; i++) {\n    int tmp = b;\n    b = a + b;\n    a = tmp;\n  }\n  return 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 {\n    if n == 1 || n == 2 { return n as i32; }\n    let (mut a, mut b) = (1, 2);\n    for _ in 3..=n {\n        let tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    b\n}\n
    climbing_stairs_dp.c
    /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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 {\n    if (n == 1 or n == 2) {\n        return @intCast(n);\n    }\n    var a: i32 = 1;\n    var b: i32 = 2;\n    for (3..n + 1) |_| {\n        var tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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\n    if i == 0 or c == 0:\n        return 0\n    # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c:\n        return knapsack_dfs(wgt, val, i - 1, c)\n    # \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    no = knapsack_dfs(wgt, val, i - 1, c)\n    yes = 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\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = knapsackDFS(wgt, val, i - 1, c);\n    int 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\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = knapsackDFS(wgt, val, i - 1, c);\n    int 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\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (weight[i - 1] > c) {\n        return KnapsackDFS(weight, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = KnapsackDFS(weight, val, i - 1, c);\n    int 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\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i-1] > c {\n        return knapsackDFS(wgt, val, i-1, c)\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    no := knapsackDFS(wgt, val, i-1, c)\n    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\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c {\n        return 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\n    let no = knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c)\n    let 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\n    return 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    const no = knapsackDFS(wgt, val, i - 1, c);\n    const 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\n    return Math.max(no, yes);\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction knapsackDFS(\n    wgt: Array<number>,\n    val: Array<number>,\n    i: number,\n    c: 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    const no = knapsackDFS(wgt, val, i - 1, c);\n    const 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\n    return 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\n  if (i == 0 || c == 0) {\n    return 0;\n  }\n  // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n  if (wgt[i - 1] > c) {\n    return knapsackDFS(wgt, val, i - 1, c);\n  }\n  // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n  int no = knapsackDFS(wgt, val, i - 1, c);\n  int 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\n  return 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\n    if i == 0 || c == 0 {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c as i32 {\n        return 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\n    let no = knapsack_dfs(wgt, val, i - 1, c);\n    let 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\n    std::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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = knapsackDFS(wgt, val, i - 1, c);\n    int 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\n    return 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\n    if (i == 0 or c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    var no = knapsackDFS(wgt, val, i - 1, c);\n    var 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\n    return @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(\n    wgt: 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\n    if i == 0 or c == 0:\n        return 0\n    # \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1:\n        return mem[i][c]\n    # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c:\n        return 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\n    no = knapsack_dfs_mem(wgt, val, mem, i - 1, c)\n    yes = 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\n    mem[i][c] = max(no, yes)\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    int no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    int 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\n    mem[i][c] = max(no, yes);\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    int no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    int 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\n    mem[i][c] = Math.max(no, yes);\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (weight[i - 1] > c) {\n        return 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\n    int no = KnapsackDFSMem(weight, val, mem, i - 1, c);\n    int 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\n    mem[i][c] = Math.Max(no, yes);\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1 {\n        return mem[i][c]\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i-1] > c {\n        return 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\n    no := knapsackDFSMem(wgt, val, mem, i-1, c)\n    yes := 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\n    mem[i][c] = int(math.Max(float64(no), float64(yes)))\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1 {\n        return mem[i][c]\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c {\n        return 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\n    let no = knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c)\n    let 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\n    mem[i][c] = max(no, yes)\n    return 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] !== -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    const no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    const yes =\n        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\n    mem[i][c] = Math.max(no, yes);\n    return mem[i][c];\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction knapsackDFSMem(\n    wgt: Array<number>,\n    val: Array<number>,\n    mem: Array<Array<number>>,\n    i: number,\n    c: 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] !== -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    const no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    const yes =\n        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\n    mem[i][c] = Math.max(no, yes);\n    return mem[i][c];\n}\n
    knapsack.dart
    /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(\n  List<int> wgt,\n  List<int> val,\n  List<List<int>> mem,\n  int i,\n  int 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\n  if (i == 0 || c == 0) {\n    return 0;\n  }\n  // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n  if (mem[i][c] != -1) {\n    return mem[i][c];\n  }\n  // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n  if (wgt[i - 1] > c) {\n    return 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\n  int no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n  int 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\n  mem[i][c] = max(no, yes);\n  return 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\n    if i == 0 || c == 0 {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1 {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c as i32 {\n        return 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\n    let no = knapsack_dfs_mem(wgt, val, mem, i - 1, c);\n    let 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\n    mem[i][c] = std::cmp::max(no, yes);\n    mem[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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    int no = knapsackDFSMem(wgt, val, memCols, mem, i - 1, c);\n    int 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\n    mem[i][c] = myMax(no, yes);\n    return 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\n    if (i == 0 or c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    var no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    var 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\n    mem[i][c] = @max(no, yes);\n    return 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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (cap + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        for c in range(1, cap + 1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    knapsack.java
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(int[] wgt, int[] val, int cap) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    knapsack.cs
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint KnapsackDP(int[] weight, int[] val, int cap) {\n    int n = weight.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (weight[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i, c] = Math.Max(dp[i - 1, c - weight[i - 1]] + val[i - 1], dp[i - 1, c]);\n            }\n        }\n    }\n    return dp[n, cap];\n}\n
    knapsack.go
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDP(wgt, val []int, cap int) int {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, cap+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        for c := 1; c <= cap; c++ {\n            if wgt[i-1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i-1][c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for c in stride(from: 1, through: cap, by: 1) {\n            if wgt[i - 1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return dp[n][cap]\n}\n
    knapsack.js
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(wgt, val, cap) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array(n + 1)\n        .fill(0)\n        .map(() => Array(cap + 1).fill(0));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i - 1][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: cap + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i - 1][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int c = 1; c <= cap; c++) {\n      if (wgt[i - 1] > c) {\n        // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n        dp[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\n        dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; cap + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for c in 1..=cap {\n            if wgt[i - 1] > c as i32 {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = std::cmp::max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    dp[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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(cap + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = myMax(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[n][cap];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    return 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 {\n    comptime var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..cap + 1) |c| {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = @max(dp[i - 1][c], dp[i - 1][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * (cap + 1)\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u5012\u5e8f\u904d\u5386\n        for c in range(cap, 0, -1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(cap + 1, 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = weight.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c > 0; c--) {\n            if (weight[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.Max(dp[c], dp[c - weight[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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 {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, cap+1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        // \u5012\u5e8f\u904d\u5386\n        for c := cap; c >= 1; c-- {\n            if wgt[i-1] <= c {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: cap + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        // \u5012\u5e8f\u904d\u5386\n        for c in stride(from: cap, through: 1, by: -1) {\n            if wgt[i - 1] <= c {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return 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) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array(cap + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (let c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[cap];\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDPComp(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array(cap + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (let c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(cap + 1, 0);\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    // \u5012\u5e8f\u904d\u5386\n    for (int c = cap; c >= 1; c--) {\n      if (wgt[i - 1] <= c) {\n        // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n        dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        // \u5012\u5e8f\u904d\u5386\n        for c in (1..=cap).rev() {\n            if wgt[i - 1] <= c as i32 {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    dp[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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(cap + 1, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[cap];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (cap + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        // \u5012\u5e8f\u904d\u5386\n        var c = cap;\n        while (c > 0) : (c -= 1) {\n            if (wgt[i - 1] < c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\u641c\u7d22\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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (cap + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        for c in range(1, cap + 1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i, c] = Math.Max(dp[i - 1, c], dp[i, c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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 {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, cap+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        for c := 1; c <= cap; c++ {\n            if wgt[i-1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i][c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for c in stride(from: 1, through: cap, by: 1) {\n            if wgt[i - 1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return dp[n][cap]\n}\n
    unbounded_knapsack.js
    /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(wgt, val, cap) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: cap + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    unbounded_knapsack.ts
    /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: cap + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int c = 1; c <= cap; c++) {\n      if (wgt[i - 1] > c) {\n        // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n        dp[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\n        dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; cap + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for c in 1..=cap {\n            if wgt[i - 1] > c as i32 {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = std::cmp::max(dp[i - 1][c], dp[i][c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(cap + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = myMax(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[n][cap];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    return 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 {\n    comptime var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..cap + 1) |c| {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = @max(dp[i - 1][c], dp[i][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * (cap + 1)\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u6b63\u5e8f\u904d\u5386\n        for c in range(1, cap + 1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(cap + 1, 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.Max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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 {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, cap+1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        for c := 1; c <= cap; c++ {\n            if wgt[i-1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: cap + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for c in stride(from: 1, through: cap, by: 1) {\n            if wgt[i - 1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return 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) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: cap + 1 }, () => 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[cap];\n}\n
    unbounded_knapsack.ts
    /* \u5b8c\u5168\u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDPComp(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: cap + 1 }, () => 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(cap + 1, 0);\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int c = 1; c <= cap; c++) {\n      if (wgt[i - 1] > c) {\n        // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n        dp[c] = dp[c];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n        dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for c in 1..=cap {\n            if wgt[i - 1] > c as i32 {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    dp[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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(cap + 1, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[cap];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (cap + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..cap + 1) |c| {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(coins)\n    MAX = amt + 1\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (amt + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a in range(1, amt + 1):\n        dp[0][a] = MAX\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in range(1, n + 1):\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\n    return 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) {\n    int n = coins.size();\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][amt + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, amt + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0, a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i, a] = Math.Min(dp[i - 1, a], dp[i, a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    max := amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, amt+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a := 1; a <= amt; a++ {\n        dp[0][a] = max\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i <= n; i++ {\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = int(math.Min(float64(dp[i-1][a]), float64(dp[i][a-coins[i-1]]+1)))\n            }\n        }\n    }\n    if dp[n][amt] != max {\n        return dp[n][amt]\n    }\n    return -1\n}\n
    coin_change.swift
    /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDP(coins: [Int], amt: Int) -> Int {\n    let n = coins.count\n    let MAX = amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a in stride(from: 1, through: amt, by: 1) {\n        dp[0][a] = MAX\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\n            }\n        }\n    }\n    return 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) {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  int MAX = amt + 1;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n  for (int a = 1; a <= amt; a++) {\n    dp[0][a] = MAX;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[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\n        dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    let max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; amt + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a in 1..= amt {\n        dp[0][a] = max;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = std::cmp::min(dp[i - 1][a], dp[i][a - coins[i - 1] as usize] + 1);\n            }\n        }\n    }\n    if 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) {\n    int n = coinsSize;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(amt + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = myMin(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    int res = dp[n][amt] != MAX ? dp[n][amt] : -1;\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    free(dp);\n    return res;\n}\n
    coin_change.zig
    // \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212\nfn coinChangeDP(comptime coins: []i32, comptime amt: usize) i32 {\n    comptime var n = coins.len;\n    comptime var max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (1..amt + 1) |a| {\n        dp[0][a] = max;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = @min(dp[i - 1][a], dp[i][a - @as(usize, @intCast(coins[i - 1]))] + 1);\n            }\n        }\n    }\n    if (dp[n][amt] != max) {\n        return @intCast(dp[n][amt]);\n    } else {\n        return -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\"\"\"\n    n = len(coins)\n    MAX = amt + 1\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [MAX] * (amt + 1)\n    dp[0] = 0\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u6b63\u5e8f\u904d\u5386\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\n    return 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) {\n    int n = coins.size();\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(amt + 1, MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    Arrays.fill(dp, MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    Array.Fill(dp, MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.Min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    max := amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, amt+1)\n    for i := 1; i <= amt; i++ {\n        dp[i] = max\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        // \u5012\u5e8f\u904d\u5386\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = int(math.Min(float64(dp[a]), float64(dp[a-coins[i-1]]+1)))\n            }\n        }\n    }\n    if dp[amt] != max {\n        return dp[amt]\n    }\n    return -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 {\n    let n = coins.count\n    let MAX = amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: MAX, count: amt + 1)\n    dp[0] = 0\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\n            }\n        }\n    }\n    return 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) {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  int MAX = amt + 1;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(amt + 1, MAX);\n  dp[0] = 0;\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[a] = dp[a];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n        dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    let max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; amt + 1];\n    dp.fill(max);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = std::cmp::min(dp[a], dp[a - coins[i - 1] as usize] + 1);\n            }\n        }\n    }\n    if 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) {\n    int n = coinsSize;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(amt + 1, sizeof(int));\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = myMin(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    int res = dp[amt] != MAX ? dp[amt] : -1;\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = coins.len;\n    comptime var max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (amt + 1);\n    @memset(&dp, max);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = @min(dp[a], dp[a - @as(usize, @intCast(coins[i - 1]))] + 1);\n            }\n        }\n    }\n    if (dp[amt] != max) {\n        return @intCast(dp[amt]);\n    } else {\n        return -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\"\"\"\n    n = len(coins)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (amt + 1) for _ in range(n + 1)]\n    # \u521d\u59cb\u5316\u9996\u5217\n    for i in range(n + 1):\n        dp[i][0] = 1\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\n    return 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) {\n    int n = coins.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][amt + 1];\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, amt + 1];\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i, 0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i, a] = dp[i - 1, a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i, a] = dp[i - 1, a] + dp[i, a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, amt+1)\n    }\n    // \u521d\u59cb\u5316\u9996\u5217\n    for i := 0; i <= n; i++ {\n        dp[i][0] = 1\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i <= n; i++ {\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i-1][a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i-1][a] + dp[i][a-coins[i-1]]\n            }\n        }\n    }\n    return 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 {\n    let n = coins.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n    // \u521d\u59cb\u5316\u9996\u5217\n    for i in stride(from: 0, through: n, by: 1) {\n        dp[i][0] = 1\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\n            }\n        }\n    }\n    return dp[n][amt]\n}\n
    coin_change_ii.js
    /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDP(coins, amt) {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (let i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (let i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n  // \u521d\u59cb\u5316\u9996\u5217\n  for (int i = 0; i <= n; i++) {\n    dp[i][0] = 1;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[i][a] = dp[i - 1][a];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n        dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; amt + 1]; n + 1];\n    // \u521d\u59cb\u5316\u9996\u5217\n    for i in 0..= n {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1] as usize];\n            }\n        }\n    }\n    dp[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) {\n    int n = coinsSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(amt + 1, sizeof(int));\n    }\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    int res = dp[n][amt];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    free(dp);\n    return 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 {\n    comptime var n = coins.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (0..n + 1) |i| {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = dp[i - 1][a] + dp[i][a - @as(usize, @intCast(coins[i - 1]))];\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(coins)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * (amt + 1)\n    dp[0] = 1\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u6b63\u5e8f\u904d\u5386\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]]\n    return 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) {\n    int n = coins.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(amt + 1, 0);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, amt+1)\n    dp[0] = 1\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        // \u5012\u5e8f\u904d\u5386\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a-coins[i-1]]\n            }\n        }\n    }\n    return 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 {\n    let n = coins.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: amt + 1)\n    dp[0] = 1\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]]\n            }\n        }\n    }\n    return 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) {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => 0);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => 0);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(amt + 1, 0);\n  dp[0] = 1;\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[a] = dp[a];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n        dp[a] = dp[a] + dp[a - coins[i - 1]];\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; amt + 1];\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = dp[a] + dp[a - coins[i - 1] as usize];\n            }\n        }\n    }\n    dp[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) {\n    int n = coinsSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(amt + 1, sizeof(int));\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    int res = dp[amt];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = coins.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (amt + 1);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = dp[a] + dp[a - @as(usize, @intCast(coins[i - 1]))];\n            }\n        }\n    }\n    return 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\u300a\u738b\u8005\u8363\u8000\u300b\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\u7684\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\"\"\"\n\n    def __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\n        self.vertices: list[int] = []\n        # \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n        self.adj_mat: list[list[int]] = []\n        # \u6dfb\u52a0\u9876\u70b9\n        for val in vertices:\n            self.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\n        for e in edges:\n            self.add_edge(e[0], e[1])\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\n        return len(self.vertices)\n\n    def add_vertex(self, val: int):\n        \"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\n        n = self.size()\n        # \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        self.vertices.append(val)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        new_row = [0] * n\n        self.adj_mat.append(new_row)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for row in self.adj_mat:\n            row.append(0)\n\n    def remove_vertex(self, index: int):\n        \"\"\"\u5220\u9664\u9876\u70b9\"\"\"\n        if index >= self.size():\n            raise IndexError()\n        # \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        self.vertices.pop(index)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        self.adj_mat.pop(index)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for row in self.adj_mat:\n            row.pop(index)\n\n    def 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\n        if i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\n            raise 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)\n        self.adj_mat[i][j] = 1\n        self.adj_mat[j][i] = 1\n\n    def 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\n        if i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\n            raise IndexError()\n        self.adj_mat[i][j] = 0\n        self.adj_mat[j][i] = 0\n\n    def print(self):\n        \"\"\"\u6253\u5370\u90bb\u63a5\u77e9\u9635\"\"\"\n        print(\"\u9876\u70b9\u5217\u8868 =\", self.vertices)\n        print(\"\u90bb\u63a5\u77e9\u9635 =\")\n        print_matrix(self.adj_mat)\n
    graph_adjacency_matrix.cpp
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\n    vector<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\n    vector<vector<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    GraphAdjMat(const vector<int> &vertices, const vector<vector<int>> &edges) {\n        // \u6dfb\u52a0\u9876\u70b9\n        for (int val : vertices) {\n            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\n        for (const vector<int> &edge : edges) {\n            addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int size() const {\n        return vertices.size();\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    void addVertex(int val) {\n        int n = size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.push_back(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        adjMat.emplace_back(vector<int>(n, 0));\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (vector<int> &row : adjMat) {\n            row.push_back(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    void removeVertex(int index) {\n        if (index >= size()) {\n            throw out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.erase(vertices.begin() + index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.erase(adjMat.begin() + index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (vector<int> &row : adjMat) {\n            row.erase(row.begin() + index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    void addEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n            throw 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)\n        adjMat[i][j] = 1;\n        adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    void removeEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n            throw out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n        }\n        adjMat[i][j] = 0;\n        adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    void print() {\n        cout << \"\u9876\u70b9\u5217\u8868 = \";\n        printVector(vertices);\n        cout << \"\u90bb\u63a5\u77e9\u9635 =\" << endl;\n        printVectorMatrix(adjMat);\n    }\n};\n
    graph_adjacency_matrix.java
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\n    List<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\n    List<List<Integer>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public GraphAdjMat(int[] vertices, int[][] edges) {\n        this.vertices = new ArrayList<>();\n        this.adjMat = new ArrayList<>();\n        // \u6dfb\u52a0\u9876\u70b9\n        for (int val : vertices) {\n            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\n        for (int[] e : edges) {\n            addEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    public int size() {\n        return vertices.size();\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void addVertex(int val) {\n        int n = size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.add(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        List<Integer> newRow = new ArrayList<>(n);\n        for (int j = 0; j < n; j++) {\n            newRow.add(0);\n        }\n        adjMat.add(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (List<Integer> row : adjMat) {\n            row.add(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void removeVertex(int index) {\n        if (index >= size())\n            throw new IndexOutOfBoundsException();\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (List<Integer> row : adjMat) {\n            row.remove(index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void addEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\n            throw 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)\n        adjMat.get(i).set(j, 1);\n        adjMat.get(j).set(i, 1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void removeEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\n            throw new IndexOutOfBoundsException();\n        adjMat.get(i).set(j, 0);\n        adjMat.get(j).set(i, 0);\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    public void print() {\n        System.out.print(\"\u9876\u70b9\u5217\u8868 = \");\n        System.out.println(vertices);\n        System.out.println(\"\u90bb\u63a5\u77e9\u9635 =\");\n        PrintUtil.printMatrix(adjMat);\n    }\n}\n
    graph_adjacency_matrix.cs
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\n    List<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\n    List<List<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u51fd\u6570 */\n    public GraphAdjMat(int[] vertices, int[][] edges) {\n        this.vertices = [];\n        this.adjMat = [];\n        // \u6dfb\u52a0\u9876\u70b9\n        foreach (int val in vertices) {\n            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\n        foreach (int[] e in edges) {\n            AddEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int Size() {\n        return vertices.Count;\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void AddVertex(int val) {\n        int n = Size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.Add(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        List<int> newRow = new(n);\n        for (int j = 0; j < n; j++) {\n            newRow.Add(0);\n        }\n        adjMat.Add(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        foreach (List<int> row in adjMat) {\n            row.Add(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void RemoveVertex(int index) {\n        if (index >= Size())\n            throw new IndexOutOfRangeException();\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.RemoveAt(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.RemoveAt(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        foreach (List<int> row in adjMat) {\n            row.RemoveAt(index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void AddEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\n            throw 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)\n        adjMat[i][j] = 1;\n        adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void RemoveEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\n            throw new IndexOutOfRangeException();\n        adjMat[i][j] = 0;\n        adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    public void Print() {\n        Console.Write(\"\u9876\u70b9\u5217\u8868 = \");\n        PrintUtil.PrintList(vertices);\n        Console.WriteLine(\"\u90bb\u63a5\u77e9\u9635 =\");\n        PrintUtil.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\n    vertices []int\n    // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n    adjMat [][]int\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {\n    // \u6dfb\u52a0\u9876\u70b9\n    n := len(vertices)\n    adjMat := make([][]int, n)\n    for i := range adjMat {\n        adjMat[i] = make([]int, n)\n    }\n    // \u521d\u59cb\u5316\u56fe\n    g := &graphAdjMat{\n        vertices: vertices,\n        adjMat:   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\n    for i := range edges {\n        g.addEdge(edges[i][0], edges[i][1])\n    }\n    return g\n}\n\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjMat) size() int {\n    return len(g.vertices)\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjMat) addVertex(val int) {\n    n := g.size()\n    // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n    g.vertices = append(g.vertices, val)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n    newRow := make([]int, n)\n    g.adjMat = append(g.adjMat, newRow)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n    for i := range g.adjMat {\n        g.adjMat[i] = append(g.adjMat[i], 0)\n    }\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjMat) removeVertex(index int) {\n    if index >= g.size() {\n        return\n    }\n    // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n    g.vertices = append(g.vertices[:index], g.vertices[index+1:]...)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n    g.adjMat = append(g.adjMat[:index], g.adjMat[index+1:]...)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n    for i := range g.adjMat {\n        g.adjMat[i] = append(g.adjMat[i][:index], g.adjMat[i][index+1:]...)\n    }\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\n    if i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\n        fmt.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)\n    g.adjMat[i][j] = 1\n    g.adjMat[j][i] = 1\n}\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\n    if i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\n        fmt.Errorf(\"%s\", \"Index Out Of Bounds Exception\")\n    }\n    g.adjMat[i][j] = 0\n    g.adjMat[j][i] = 0\n}\n\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nfunc (g *graphAdjMat) print() {\n    fmt.Printf(\"\\t\u9876\u70b9\u5217\u8868 = %v\\n\", g.vertices)\n    fmt.Printf(\"\\t\u90bb\u63a5\u77e9\u9635 = \\n\")\n    for i := range g.adjMat {\n        fmt.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 {\n    private 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\n    private var adjMat: [[Int]] // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init(vertices: [Int], edges: [[Int]]) {\n        self.vertices = []\n        adjMat = []\n        // \u6dfb\u52a0\u9876\u70b9\n        for val in vertices {\n            addVertex(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\n        for e in edges {\n            addEdge(i: e[0], j: e[1])\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    func size() -> Int {\n        vertices.count\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    func addVertex(val: Int) {\n        let n = size()\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.append(val)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        let newRow = Array(repeating: 0, count: n)\n        adjMat.append(newRow)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for i in adjMat.indices {\n            adjMat[i].append(0)\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    func removeVertex(index: Int) {\n        if index >= size() {\n            fatalError(\"\u8d8a\u754c\")\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.remove(at: index)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.remove(at: index)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for i in adjMat.indices {\n            adjMat[i].remove(at: index)\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    func addEdge(i: Int, j: Int) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if i < 0 || j < 0 || i >= size() || j >= size() || i == j {\n            fatalError(\"\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)\n        adjMat[i][j] = 1\n        adjMat[j][i] = 1\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    func removeEdge(i: Int, j: Int) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if i < 0 || j < 0 || i >= size() || j >= size() || i == j {\n            fatalError(\"\u8d8a\u754c\")\n        }\n        adjMat[i][j] = 0\n        adjMat[j][i] = 0\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    func print() {\n        Swift.print(\"\u9876\u70b9\u5217\u8868 = \", terminator: \"\")\n        Swift.print(vertices)\n        Swift.print(\"\u90bb\u63a5\u77e9\u9635 =\")\n        PrintUtil.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 {\n    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\n    adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u51fd\u6570 */\n    constructor(vertices, edges) {\n        this.vertices = [];\n        this.adjMat = [];\n        // \u6dfb\u52a0\u9876\u70b9\n        for (const val of vertices) {\n            this.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\n        for (const e of edges) {\n            this.addEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size() {\n        return this.vertices.length;\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(val) {\n        const n = this.size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        this.vertices.push(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        const newRow = [];\n        for (let j = 0; j < n; j++) {\n            newRow.push(0);\n        }\n        this.adjMat.push(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (const row of this.adjMat) {\n            row.push(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(index) {\n        if (index >= this.size()) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        this.vertices.splice(index, 1);\n\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        this.adjMat.splice(index, 1);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (const row of this.adjMat) {\n            row.splice(index, 1);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    addEdge(i, j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw 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)\n        this.adjMat[i][j] = 1;\n        this.adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    removeEdge(i, j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        this.adjMat[i][j] = 0;\n        this.adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    print() {\n        console.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\n        console.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 {\n    vertices: 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\n    adjMat: number[][]; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u51fd\u6570 */\n    constructor(vertices: number[], edges: number[][]) {\n        this.vertices = [];\n        this.adjMat = [];\n        // \u6dfb\u52a0\u9876\u70b9\n        for (const val of vertices) {\n            this.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\n        for (const e of edges) {\n            this.addEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size(): number {\n        return this.vertices.length;\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(val: number): void {\n        const n: number = this.size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        this.vertices.push(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        const newRow: number[] = [];\n        for (let j: number = 0; j < n; j++) {\n            newRow.push(0);\n        }\n        this.adjMat.push(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (const row of this.adjMat) {\n            row.push(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(index: number): void {\n        if (index >= this.size()) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        this.vertices.splice(index, 1);\n\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        this.adjMat.splice(index, 1);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (const row of this.adjMat) {\n            row.splice(index, 1);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    addEdge(i: number, j: number): void {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw 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)\n        this.adjMat[i][j] = 1;\n        this.adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    removeEdge(i: number, j: number): void {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        this.adjMat[i][j] = 0;\n        this.adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    print(): void {\n        console.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\n        console.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 {\n  List<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\n  List<List<int>> adjMat = []; //\u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  GraphAdjMat(List<int> vertices, List<List<int>> edges) {\n    this.vertices = [];\n    this.adjMat = [];\n    // \u6dfb\u52a0\u9876\u70b9\n    for (int val in vertices) {\n      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\n    for (List<int> e in edges) {\n      addEdge(e[0], e[1]);\n    }\n  }\n\n  /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n  int size() {\n    return vertices.length;\n  }\n\n  /* \u6dfb\u52a0\u9876\u70b9 */\n  void addVertex(int val) {\n    int n = size();\n    // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n    vertices.add(val);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n    List<int> newRow = List.filled(n, 0, growable: true);\n    adjMat.add(newRow);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n    for (List<int> row in adjMat) {\n      row.add(0);\n    }\n  }\n\n  /* \u5220\u9664\u9876\u70b9 */\n  void removeVertex(int index) {\n    if (index >= size()) {\n      throw IndexError;\n    }\n    // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n    vertices.removeAt(index);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n    adjMat.removeAt(index);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n    for (List<int> row in adjMat) {\n      row.removeAt(index);\n    }\n  }\n\n  /* \u6dfb\u52a0\u8fb9 */\n  // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n  void addEdge(int i, int j) {\n    // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n    if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n      throw 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)\n    adjMat[i][j] = 1;\n    adjMat[j][i] = 1;\n  }\n\n  /* \u5220\u9664\u8fb9 */\n  // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n  void removeEdge(int i, int j) {\n    // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n    if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n      throw IndexError;\n    }\n    adjMat[i][j] = 0;\n    adjMat[j][i] = 0;\n  }\n\n  /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n  void printAdjMat() {\n    print(\"\u9876\u70b9\u5217\u8868 = $vertices\");\n    print(\"\u90bb\u63a5\u77e9\u9635 = \");\n    printMatrix(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\n    pub vertices: Vec<i32>,\n    // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n    pub adj_mat: Vec<Vec<i32>>,\n}\n\nimpl GraphAdjMat {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(vertices: Vec<i32>, edges: Vec<[usize; 2]>) -> Self {\n        let mut graph = GraphAdjMat {\n            vertices: vec![],\n            adj_mat: vec![],\n        };\n        // \u6dfb\u52a0\u9876\u70b9\n        for val in vertices {\n            graph.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\n        for edge in edges {\n            graph.add_edge(edge[0], edge[1])\n        }\n\n        graph\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    pub fn size(&self) -> usize {\n        self.vertices.len()\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    pub fn add_vertex(&mut self, val: i32) {\n        let n = self.size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        self.vertices.push(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        self.adj_mat.push(vec![0; n]);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for row in &mut self.adj_mat {\n            row.push(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    pub fn remove_vertex(&mut self, index: usize) {\n        if index >= self.size() {\n            panic!(\"index error\")\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        self.vertices.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        self.adj_mat.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for row in &mut self.adj_mat {\n            row.remove(index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    pub 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\n        if i >= self.size() || j >= self.size() || i == j {\n            panic!(\"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)\n        self.adj_mat[i][j] = 1;\n        self.adj_mat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    pub 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\n        if i >= self.size() || j >= self.size() || i == j {\n            panic!(\"index error\")\n        }\n        self.adj_mat[i][j] = 0;\n        self.adj_mat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    pub fn print(&self) {\n        println!(\"\u9876\u70b9\u5217\u8868 = {:?}\", self.vertices);\n        println!(\"\u90bb\u63a5\u77e9\u9635 =\");\n        println!(\"[\");\n        for row in &self.adj_mat {\n            println!(\"  {:?},\", row);\n        }\n        println!(\"]\")\n    }\n}\n
    graph_adjacency_matrix.c
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7ed3\u6784\u4f53 */\ntypedef struct {\n    int vertices[MAX_SIZE];\n    int adjMat[MAX_SIZE][MAX_SIZE];\n    int size;\n} GraphAdjMat;\n\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjMat *newGraphAdjMat() {\n    GraphAdjMat *graph = (GraphAdjMat *)malloc(sizeof(GraphAdjMat));\n    graph->size = 0;\n    for (int i = 0; i < MAX_SIZE; i++) {\n        for (int j = 0; j < MAX_SIZE; j++) {\n            graph->adjMat[i][j] = 0;\n        }\n    }\n    return graph;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjMat(GraphAdjMat *graph) {\n    free(graph);\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjMat *graph, int val) {\n    if (graph->size == MAX_SIZE) {\n        fprintf(stderr, \"\u56fe\u7684\u9876\u70b9\u6570\u91cf\u5df2\u8fbe\u6700\u5927\u503c\\n\");\n        return;\n    }\n    // \u6dfb\u52a0\u7b2c n \u4e2a\u9876\u70b9\uff0c\u5e76\u5c06\u7b2c n \u884c\u548c\u5217\u7f6e\u96f6\n    int n = graph->size;\n    graph->vertices[n] = val;\n    for (int i = 0; i <= n; i++) {\n        graph->adjMat[n][i] = graph->adjMat[i][n] = 0;\n    }\n    graph->size++;\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjMat *graph, int index) {\n    if (index < 0 || index >= graph->size) {\n        fprintf(stderr, \"\u9876\u70b9\u7d22\u5f15\u8d8a\u754c\\n\");\n        return;\n    }\n    // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n    for (int i = index; i < graph->size - 1; i++) {\n        graph->vertices[i] = graph->vertices[i + 1];\n    }\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n    for (int i = index; i < graph->size - 1; i++) {\n        for (int j = 0; j < graph->size; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i + 1][j];\n        }\n    }\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n    for (int i = 0; i < graph->size; i++) {\n        for (int j = index; j < graph->size - 1; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i][j + 1];\n        }\n    }\n    graph->size--;\n}\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) {\n    if (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\n        fprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\n        return;\n    }\n    graph->adjMat[i][j] = 1;\n    graph->adjMat[j][i] = 1;\n}\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) {\n    if (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\n        fprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\n        return;\n    }\n    graph->adjMat[i][j] = 0;\n    graph->adjMat[j][i] = 0;\n}\n\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid printGraphAdjMat(GraphAdjMat *graph) {\n    printf(\"\u9876\u70b9\u5217\u8868 = \");\n    printArray(graph->vertices, graph->size);\n    printf(\"\u90bb\u63a5\u77e9\u9635 =\\n\");\n    for (int i = 0; i < graph->size; i++) {\n        printArray(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\"\"\"\n\n    def __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\n        self.adj_list = dict[Vertex, list[Vertex]]()\n        # \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for edge in edges:\n            self.add_vertex(edge[0])\n            self.add_vertex(edge[1])\n            self.add_edge(edge[0], edge[1])\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\n        return len(self.adj_list)\n\n    def add_edge(self, vet1: Vertex, vet2: Vertex):\n        \"\"\"\u6dfb\u52a0\u8fb9\"\"\"\n        if vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\n            raise ValueError()\n        # \u6dfb\u52a0\u8fb9 vet1 - vet2\n        self.adj_list[vet1].append(vet2)\n        self.adj_list[vet2].append(vet1)\n\n    def remove_edge(self, vet1: Vertex, vet2: Vertex):\n        \"\"\"\u5220\u9664\u8fb9\"\"\"\n        if vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\n            raise ValueError()\n        # \u5220\u9664\u8fb9 vet1 - vet2\n        self.adj_list[vet1].remove(vet2)\n        self.adj_list[vet2].remove(vet1)\n\n    def add_vertex(self, vet: Vertex):\n        \"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\n        if vet in self.adj_list:\n            return\n        # \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        self.adj_list[vet] = []\n\n    def remove_vertex(self, vet: Vertex):\n        \"\"\"\u5220\u9664\u9876\u70b9\"\"\"\n        if vet not in self.adj_list:\n            raise ValueError()\n        # \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        self.adj_list.pop(vet)\n        # \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for vertex in self.adj_list:\n            if vet in self.adj_list[vertex]:\n                self.adj_list[vertex].remove(vet)\n\n    def print(self):\n        \"\"\"\u6253\u5370\u90bb\u63a5\u8868\"\"\"\n        print(\"\u90bb\u63a5\u8868 =\")\n        for vertex in self.adj_list:\n            tmp = [v.val for v in self.adj_list[vertex]]\n            print(f\"{vertex.val}: {tmp},\")\n
    graph_adjacency_list.cpp
    /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n  public:\n    // \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    unordered_map<Vertex *, vector<Vertex *>> adjList;\n\n    /* \u5728 vector \u4e2d\u5220\u9664\u6307\u5b9a\u8282\u70b9 */\n    void remove(vector<Vertex *> &vec, Vertex *vet) {\n        for (int i = 0; i < vec.size(); i++) {\n            if (vec[i] == vet) {\n                vec.erase(vec.begin() + i);\n                break;\n            }\n        }\n    }\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    GraphAdjList(const vector<vector<Vertex *>> &edges) {\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (const vector<Vertex *> &edge : edges) {\n            addVertex(edge[0]);\n            addVertex(edge[1]);\n            addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int size() {\n        return adjList.size();\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    void addEdge(Vertex *vet1, Vertex *vet2) {\n        if (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\n            throw invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList[vet1].push_back(vet2);\n        adjList[vet2].push_back(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    void removeEdge(Vertex *vet1, Vertex *vet2) {\n        if (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\n            throw invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        remove(adjList[vet1], vet2);\n        remove(adjList[vet2], vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    void addVertex(Vertex *vet) {\n        if (adjList.count(vet))\n            return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList[vet] = vector<Vertex *>();\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    void removeVertex(Vertex *vet) {\n        if (!adjList.count(vet))\n            throw invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.erase(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (auto &adj : adjList) {\n            remove(adj.second, vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    void print() {\n        cout << \"\u90bb\u63a5\u8868 =\" << endl;\n        for (auto &adj : adjList) {\n            const auto &key = adj.first;\n            const auto &vec = adj.second;\n            cout << key->val << \": \";\n            printVector(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\n    Map<Vertex, List<Vertex>> adjList;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public GraphAdjList(Vertex[][] edges) {\n        this.adjList = new HashMap<>();\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (Vertex[] edge : edges) {\n            addVertex(edge[0]);\n            addVertex(edge[1]);\n            addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    public int size() {\n        return adjList.size();\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    public void addEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\n            throw new IllegalArgumentException();\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList.get(vet1).add(vet2);\n        adjList.get(vet2).add(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    public void removeEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\n            throw new IllegalArgumentException();\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        adjList.get(vet1).remove(vet2);\n        adjList.get(vet2).remove(vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void addVertex(Vertex vet) {\n        if (adjList.containsKey(vet))\n            return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList.put(vet, new ArrayList<>());\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void removeVertex(Vertex vet) {\n        if (!adjList.containsKey(vet))\n            throw new IllegalArgumentException();\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.remove(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (List<Vertex> list : adjList.values()) {\n            list.remove(vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    public void print() {\n        System.out.println(\"\u90bb\u63a5\u8868 =\");\n        for (Map.Entry<Vertex, List<Vertex>> pair : adjList.entrySet()) {\n            List<Integer> tmp = new ArrayList<>();\n            for (Vertex vertex : pair.getValue())\n                tmp.add(vertex.val);\n            System.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\n    public Dictionary<Vertex, List<Vertex>> adjList;\n\n    /* \u6784\u9020\u51fd\u6570 */\n    public GraphAdjList(Vertex[][] edges) {\n        adjList = [];\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        foreach (Vertex[] edge in edges) {\n            AddVertex(edge[0]);\n            AddVertex(edge[1]);\n            AddEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int Size() {\n        return adjList.Count;\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    public void AddEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\n            throw new InvalidOperationException();\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList[vet1].Add(vet2);\n        adjList[vet2].Add(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    public void RemoveEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\n            throw new InvalidOperationException();\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        adjList[vet1].Remove(vet2);\n        adjList[vet2].Remove(vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void AddVertex(Vertex vet) {\n        if (adjList.ContainsKey(vet))\n            return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList.Add(vet, []);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void RemoveVertex(Vertex vet) {\n        if (!adjList.ContainsKey(vet))\n            throw new InvalidOperationException();\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.Remove(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        foreach (List<Vertex> list in adjList.Values) {\n            list.Remove(vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    public void Print() {\n        Console.WriteLine(\"\u90bb\u63a5\u8868 =\");\n        foreach (KeyValuePair<Vertex, List<Vertex>> pair in adjList) {\n            List<int> tmp = [];\n            foreach (Vertex vertex in pair.Value)\n                tmp.Add(vertex.val);\n            Console.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\n    adjList map[Vertex][]Vertex\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjList(edges [][]Vertex) *graphAdjList {\n    g := &graphAdjList{\n        adjList: make(map[Vertex][]Vertex),\n    }\n    // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n    for _, edge := range edges {\n        g.addVertex(edge[0])\n        g.addVertex(edge[1])\n        g.addEdge(edge[0], edge[1])\n    }\n    return g\n}\n\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjList) size() int {\n    return len(g.adjList)\n}\n\n/* \u6dfb\u52a0\u8fb9 */\nfunc (g *graphAdjList) addEdge(vet1 Vertex, vet2 Vertex) {\n    _, ok1 := g.adjList[vet1]\n    _, ok2 := g.adjList[vet2]\n    if !ok1 || !ok2 || vet1 == vet2 {\n        panic(\"error\")\n    }\n    // \u6dfb\u52a0\u8fb9 vet1 - vet2, \u6dfb\u52a0\u533f\u540d struct{},\n    g.adjList[vet1] = append(g.adjList[vet1], vet2)\n    g.adjList[vet2] = append(g.adjList[vet2], vet1)\n}\n\n/* \u5220\u9664\u8fb9 */\nfunc (g *graphAdjList) removeEdge(vet1 Vertex, vet2 Vertex) {\n    _, ok1 := g.adjList[vet1]\n    _, ok2 := g.adjList[vet2]\n    if !ok1 || !ok2 || vet1 == vet2 {\n        panic(\"error\")\n    }\n    // \u5220\u9664\u8fb9 vet1 - vet2\n    g.adjList[vet1] = DeleteSliceElms(g.adjList[vet1], vet2)\n    g.adjList[vet2] = DeleteSliceElms(g.adjList[vet2], vet1)\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjList) addVertex(vet Vertex) {\n    _, ok := g.adjList[vet]\n    if ok {\n        return\n    }\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n    g.adjList[vet] = make([]Vertex, 0)\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjList) removeVertex(vet Vertex) {\n    _, ok := g.adjList[vet]\n    if !ok {\n        panic(\"error\")\n    }\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n    delete(g.adjList, vet)\n    // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n    for v, list := range g.adjList {\n        g.adjList[v] = DeleteSliceElms(list, vet)\n    }\n}\n\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nfunc (g *graphAdjList) print() {\n    var builder strings.Builder\n    fmt.Printf(\"\u90bb\u63a5\u8868 = \\n\")\n    for k, v := range g.adjList {\n        builder.WriteString(\"\\t\\t\" + strconv.Itoa(k.Val) + \": \")\n        for _, vet := range v {\n            builder.WriteString(strconv.Itoa(vet.Val) + \" \")\n        }\n        fmt.Println(builder.String())\n        builder.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\n    public private(set) var adjList: [Vertex: [Vertex]]\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public init(edges: [[Vertex]]) {\n        adjList = [:]\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for edge in edges {\n            addVertex(vet: edge[0])\n            addVertex(vet: edge[1])\n            addEdge(vet1: edge[0], vet2: edge[1])\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    public func size() -> Int {\n        adjList.count\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    public func addEdge(vet1: Vertex, vet2: Vertex) {\n        if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\n            fatalError(\"\u53c2\u6570\u9519\u8bef\")\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList[vet1]?.append(vet2)\n        adjList[vet2]?.append(vet1)\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    public func removeEdge(vet1: Vertex, vet2: Vertex) {\n        if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\n            fatalError(\"\u53c2\u6570\u9519\u8bef\")\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        adjList[vet1]?.removeAll(where: { $0 == vet2 })\n        adjList[vet2]?.removeAll(where: { $0 == vet1 })\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public func addVertex(vet: Vertex) {\n        if adjList[vet] != nil {\n            return\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList[vet] = []\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public func removeVertex(vet: Vertex) {\n        if adjList[vet] == nil {\n            fatalError(\"\u53c2\u6570\u9519\u8bef\")\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.removeValue(forKey: vet)\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for key in adjList.keys {\n            adjList[key]?.removeAll(where: { $0 == vet })\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    public func print() {\n        Swift.print(\"\u90bb\u63a5\u8868 =\")\n        for pair in adjList {\n            var tmp: [Int] = []\n            for vertex in pair.value {\n                tmp.append(vertex.val)\n            }\n            Swift.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\n    adjList;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(edges) {\n        this.adjList = new Map();\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (const edge of edges) {\n            this.addVertex(edge[0]);\n            this.addVertex(edge[1]);\n            this.addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size() {\n        return this.adjList.size;\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    addEdge(vet1, vet2) {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).push(vet2);\n        this.adjList.get(vet2).push(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    removeEdge(vet1, vet2) {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\n        this.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(vet) {\n        if (this.adjList.has(vet)) return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        this.adjList.set(vet, []);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(vet) {\n        if (!this.adjList.has(vet)) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        this.adjList.delete(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (const set of this.adjList.values()) {\n            const index = set.indexOf(vet);\n            if (index > -1) {\n                set.splice(index, 1);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    print() {\n        console.log('\u90bb\u63a5\u8868 =');\n        for (const [key, value] of this.adjList) {\n            const tmp = [];\n            for (const vertex of value) {\n                tmp.push(vertex.val);\n            }\n            console.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\n    adjList: Map<Vertex, Vertex[]>;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(edges: Vertex[][]) {\n        this.adjList = new Map();\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (const edge of edges) {\n            this.addVertex(edge[0]);\n            this.addVertex(edge[1]);\n            this.addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size(): number {\n        return this.adjList.size;\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    addEdge(vet1: Vertex, vet2: Vertex): void {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).push(vet2);\n        this.adjList.get(vet2).push(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    removeEdge(vet1: Vertex, vet2: Vertex): void {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\n        this.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(vet: Vertex): void {\n        if (this.adjList.has(vet)) return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        this.adjList.set(vet, []);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(vet: Vertex): void {\n        if (!this.adjList.has(vet)) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        this.adjList.delete(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (const set of this.adjList.values()) {\n            const index: number = set.indexOf(vet);\n            if (index > -1) {\n                set.splice(index, 1);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    print(): void {\n        console.log('\u90bb\u63a5\u8868 =');\n        for (const [key, value] of this.adjList.entries()) {\n            const tmp = [];\n            for (const vertex of value) {\n                tmp.push(vertex.val);\n            }\n            console.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\n  Map<Vertex, List<Vertex>> adjList = {};\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  GraphAdjList(List<List<Vertex>> edges) {\n    for (List<Vertex> edge in edges) {\n      addVertex(edge[0]);\n      addVertex(edge[1]);\n      addEdge(edge[0], edge[1]);\n    }\n  }\n\n  /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n  int size() {\n    return adjList.length;\n  }\n\n  /* \u6dfb\u52a0\u8fb9 */\n  void addEdge(Vertex vet1, Vertex vet2) {\n    if (!adjList.containsKey(vet1) ||\n        !adjList.containsKey(vet2) ||\n        vet1 == vet2) {\n      throw ArgumentError;\n    }\n    // \u6dfb\u52a0\u8fb9 vet1 - vet2\n    adjList[vet1]!.add(vet2);\n    adjList[vet2]!.add(vet1);\n  }\n\n  /* \u5220\u9664\u8fb9 */\n  void removeEdge(Vertex vet1, Vertex vet2) {\n    if (!adjList.containsKey(vet1) ||\n        !adjList.containsKey(vet2) ||\n        vet1 == vet2) {\n      throw ArgumentError;\n    }\n    // \u5220\u9664\u8fb9 vet1 - vet2\n    adjList[vet1]!.remove(vet2);\n    adjList[vet2]!.remove(vet1);\n  }\n\n  /* \u6dfb\u52a0\u9876\u70b9 */\n  void addVertex(Vertex vet) {\n    if (adjList.containsKey(vet)) return;\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n    adjList[vet] = [];\n  }\n\n  /* \u5220\u9664\u9876\u70b9 */\n  void removeVertex(Vertex vet) {\n    if (!adjList.containsKey(vet)) {\n      throw ArgumentError;\n    }\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n    adjList.remove(vet);\n    // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n    adjList.forEach((key, value) {\n      value.remove(vet);\n    });\n  }\n\n  /* \u6253\u5370\u90bb\u63a5\u8868 */\n  void printAdjList() {\n    print(\"\u90bb\u63a5\u8868 =\");\n    adjList.forEach((key, value) {\n      List<int> tmp = [];\n      for (Vertex vertex in value) {\n        tmp.add(vertex.val);\n      }\n      print(\"${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\n    pub adj_list: HashMap<Vertex, Vec<Vertex>>,\n}\n\nimpl GraphAdjList {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(edges: Vec<[Vertex; 2]>) -> Self {\n        let mut graph = GraphAdjList {\n            adj_list: HashMap::new(),\n        };\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for edge in edges {\n            graph.add_vertex(edge[0]);\n            graph.add_vertex(edge[1]);\n            graph.add_edge(edge[0], edge[1]);\n        }\n\n        graph\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    #[allow(unused)]\n    pub fn size(&self) -> usize {\n        self.adj_list.len()\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    pub fn add_edge(&mut self, vet1: Vertex, vet2: Vertex) {\n        if !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n        {\n            panic!(\"value error\");\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        self.adj_list.get_mut(&vet1).unwrap().push(vet2);\n        self.adj_list.get_mut(&vet2).unwrap().push(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    #[allow(unused)]\n    pub fn remove_edge(&mut self, vet1: Vertex, vet2: Vertex) {\n        if !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n        {\n            panic!(\"value error\");\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        self.adj_list\n            .get_mut(&vet1)\n            .unwrap()\n            .retain(|&vet| vet != vet2);\n        self.adj_list\n            .get_mut(&vet2)\n            .unwrap()\n            .retain(|&vet| vet != vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    pub fn add_vertex(&mut self, vet: Vertex) {\n        if self.adj_list.contains_key(&vet) {\n            return;\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        self.adj_list.insert(vet, vec![]);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    #[allow(unused)]\n    pub fn remove_vertex(&mut self, vet: Vertex) {\n        if !self.adj_list.contains_key(&vet) {\n            panic!(\"value error\");\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        self.adj_list.remove(&vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for list in self.adj_list.values_mut() {\n            list.retain(|&v| v != vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    pub fn print(&self) {\n        println!(\"\u90bb\u63a5\u8868 =\");\n        for (vertex, list) in &self.adj_list {\n            let list = list.iter().map(|vertex| vertex.val).collect::<Vec<i32>>();\n            println!(\"{}: {:?},\", vertex.val, list);\n        }\n    }\n}\n
    graph_adjacency_list.c
    /* \u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct AdjListNode {\n    Vertex *vertex;           // \u9876\u70b9\n    struct AdjListNode *next; // \u540e\u7ee7\u8282\u70b9\n} AdjListNode;\n\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\n    for (int i = 0; i < graph->size; i++) {\n        if (graph->heads[i]->vertex == vet) {\n            return graph->heads[i];\n        }\n    }\n    return NULL;\n}\n\n/* \u6dfb\u52a0\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid addEdgeHelper(AdjListNode *head, Vertex *vet) {\n    AdjListNode *node = (AdjListNode *)malloc(sizeof(AdjListNode));\n    node->vertex = vet;\n    // \u5934\u63d2\u6cd5\n    node->next = head->next;\n    head->next = node;\n}\n\n/* \u5220\u9664\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid removeEdgeHelper(AdjListNode *head, Vertex *vet) {\n    AdjListNode *pre = head;\n    AdjListNode *cur = head->next;\n    // \u5728\u94fe\u8868\u4e2d\u641c\u7d22 vet \u5bf9\u5e94\u8282\u70b9\n    while (cur != NULL && cur->vertex != vet) {\n        pre = cur;\n        cur = cur->next;\n    }\n    if (cur == NULL)\n        return;\n    // \u5c06 vet \u5bf9\u5e94\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u5220\u9664\n    pre->next = cur->next;\n    // \u91ca\u653e\u5185\u5b58\n    free(cur);\n}\n\n/* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntypedef struct {\n    AdjListNode *heads[MAX_SIZE]; // \u8282\u70b9\u6570\u7ec4\n    int size;                     // \u8282\u70b9\u6570\u91cf\n} GraphAdjList;\n\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjList *newGraphAdjList() {\n    GraphAdjList *graph = (GraphAdjList *)malloc(sizeof(GraphAdjList));\n    if (!graph) {\n        return NULL;\n    }\n    graph->size = 0;\n    for (int i = 0; i < MAX_SIZE; i++) {\n        graph->heads[i] = NULL;\n    }\n    return graph;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjList(GraphAdjList *graph) {\n    for (int i = 0; i < graph->size; i++) {\n        AdjListNode *cur = graph->heads[i];\n        while (cur != NULL) {\n            AdjListNode *next = cur->next;\n            if (cur != graph->heads[i]) {\n                free(cur);\n            }\n            cur = next;\n        }\n        free(graph->heads[i]->vertex);\n        free(graph->heads[i]);\n    }\n    free(graph);\n}\n\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\n    for (int i = 0; i < graph->size; i++) {\n        if (graph->heads[i]->vertex == vet) {\n            return graph->heads[i];\n        }\n    }\n    return NULL;\n}\n\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\n    AdjListNode *head1 = findNode(graph, vet1);\n    AdjListNode *head2 = findNode(graph, vet2);\n    assert(head1 != NULL && head2 != NULL && head1 != head2);\n    // \u6dfb\u52a0\u8fb9 vet1 - vet2\n    addEdgeHelper(head1, vet2);\n    addEdgeHelper(head2, vet1);\n}\n\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\n    AdjListNode *head1 = findNode(graph, vet1);\n    AdjListNode *head2 = findNode(graph, vet2);\n    assert(head1 != NULL && head2 != NULL);\n    // \u5220\u9664\u8fb9 vet1 - vet2\n    removeEdgeHelper(head1, head2->vertex);\n    removeEdgeHelper(head2, head1->vertex);\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjList *graph, Vertex *vet) {\n    assert(graph != NULL && graph->size < MAX_SIZE);\n    AdjListNode *head = (AdjListNode *)malloc(sizeof(AdjListNode));\n    head->vertex = vet;\n    head->next = NULL;\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n    graph->heads[graph->size++] = head;\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjList *graph, Vertex *vet) {\n    AdjListNode *node = findNode(graph, vet);\n    assert(node != NULL);\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n    AdjListNode *cur = node, *pre = NULL;\n    while (cur) {\n        pre = cur;\n        cur = cur->next;\n        free(pre);\n    }\n    // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n    for (int i = 0; i < graph->size; i++) {\n        cur = graph->heads[i];\n        pre = NULL;\n        while (cur) {\n            pre = cur;\n            cur = cur->next;\n            if (cur && cur->vertex == vet) {\n                pre->next = cur->next;\n                free(cur);\n                break;\n            }\n        }\n    }\n    // \u5c06\u8be5\u9876\u70b9\u4e4b\u540e\u7684\u9876\u70b9\u5411\u524d\u79fb\u52a8\uff0c\u4ee5\u586b\u8865\u7a7a\u7f3a\n    int i;\n    for (i = 0; i < graph->size; i++) {\n        if (graph->heads[i] == node)\n            break;\n    }\n    for (int j = i; j < graph->size - 1; j++) {\n        graph->heads[j] = graph->heads[j + 1];\n    }\n    graph->size--;\n    free(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\u4e5f\u53ef\u5206\u4e3a\u4e24\u79cd\uff1a\u300c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u300d\u548c\u300c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u300d\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\"\"\"\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\n    res = []\n    # \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited = set[Vertex]([start_vet])\n    # \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    que = deque[Vertex]([start_vet])\n    # \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while len(que) > 0:\n        vet = que.popleft()  # \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        # \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for adj_vet in graph.adj_list[vet]:\n            if adj_vet in visited:\n                continue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            que.append(adj_vet)  # \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.add(adj_vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    # \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n
    graph_bfs.cpp
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    vector<Vertex *> res;\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    unordered_set<Vertex *> visited = {startVet};\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    queue<Vertex *> que;\n    que.push(startVet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (!que.empty()) {\n        Vertex *vet = que.front();\n        que.pop();          // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push_back(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (auto adjVet : graph.adjList[vet]) {\n            if (visited.count(adjVet))\n                continue;            // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            que.push(adjVet);        // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.emplace(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.java
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = new ArrayList<>();\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    Set<Vertex> visited = new HashSet<>();\n    visited.add(startVet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    Queue<Vertex> que = new LinkedList<>();\n    que.offer(startVet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (!que.isEmpty()) {\n        Vertex vet = que.poll(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.add(vet);            // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (Vertex adjVet : graph.adjList.get(vet)) {\n            if (visited.contains(adjVet))\n                continue;        // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            que.offer(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.cs
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    HashSet<Vertex> visited = [startVet];\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    Queue<Vertex> que = new();\n    que.Enqueue(startVet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (que.Count > 0) {\n        Vertex vet = que.Dequeue(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.Add(vet);               // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        foreach (Vertex adjVet in graph.adjList[vet]) {\n            if (visited.Contains(adjVet)) {\n                continue;          // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.Enqueue(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.Add(adjVet);   // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.go
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    res := make([]Vertex, 0)\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited := make(map[Vertex]struct{})\n    visited[startVet] = struct{}{}\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS, \u4f7f\u7528\u5207\u7247\u6a21\u62df\u961f\u5217\n    queue := make([]Vertex, 0)\n    queue = append(queue, startVet)\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    for len(queue) > 0 {\n        // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        vet := queue[0]\n        queue = queue[1:]\n        // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        res = append(res, vet)\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for _, adjVet := range g.adjList[vet] {\n            _, isExist := visited[adjVet]\n            // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            if !isExist {\n                queue = append(queue, adjVet)\n                visited[adjVet] = struct{}{}\n            }\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n}\n
    graph_bfs.swift
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    var res: [Vertex] = []\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    var visited: Set<Vertex> = [startVet]\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    var que: [Vertex] = [startVet]\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while !que.isEmpty {\n        let vet = que.removeFirst() // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for adjVet in graph.adjList[vet] ?? [] {\n            if visited.contains(adjVet) {\n                continue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.append(adjVet) // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.insert(adjVet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n}\n
    graph_bfs.js
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited = new Set();\n    visited.add(startVet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    const que = [startVet];\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (que.length) {\n        const vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (const adjVet of graph.adjList.get(vet) ?? []) {\n            if (visited.has(adjVet)) {\n                continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.ts
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res: Vertex[] = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited: Set<Vertex> = new Set();\n    visited.add(startVet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    const que = [startVet];\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (que.length) {\n        const vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (const adjVet of graph.adjList.get(vet) ?? []) {\n            if (visited.has(adjVet)) {\n                continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\n            visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.dart
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n  List<Vertex> res = [];\n  // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n  Set<Vertex> visited = {};\n  visited.add(startVet);\n  // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n  Queue<Vertex> que = Queue();\n  que.add(startVet);\n  // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n  while (que.isNotEmpty) {\n    Vertex vet = que.removeFirst(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n    res.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (Vertex adjVet in graph.adjList[vet]!) {\n      if (visited.contains(adjVet)) {\n        continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n      }\n      que.add(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n      visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    }\n  }\n  // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n  return res;\n}\n
    graph_bfs.rs
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    let mut res = vec![];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    let mut visited = HashSet::new();\n    visited.insert(start_vet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    let mut que = VecDeque::new();\n    que.push_back(start_vet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while !que.is_empty() {\n        let vet = que.pop_front().unwrap(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n                    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        if let Some(adj_vets) = graph.adj_list.get(&vet) {\n            for &adj_vet in adj_vets {\n                if visited.contains(&adj_vet) {\n                    continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n                }\n                que.push_back(adj_vet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n                visited.insert(adj_vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n            }\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    res\n}\n
    graph_bfs.c
    /* \u8282\u70b9\u961f\u5217\u7ed3\u6784\u4f53 */\ntypedef struct {\n    Vertex *vertices[MAX_SIZE];\n    int front, rear, size;\n} Queue;\n\n/* \u6784\u9020\u51fd\u6570 */\nQueue *newQueue() {\n    Queue *q = (Queue *)malloc(sizeof(Queue));\n    q->front = q->rear = q->size = 0;\n    return q;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nint isEmpty(Queue *q) {\n    return q->size == 0;\n}\n\n/* \u5165\u961f\u64cd\u4f5c */\nvoid enqueue(Queue *q, Vertex *vet) {\n    q->vertices[q->rear] = vet;\n    q->rear = (q->rear + 1) % MAX_SIZE;\n    q->size++;\n}\n\n/* \u51fa\u961f\u64cd\u4f5c */\nVertex *dequeue(Queue *q) {\n    Vertex *vet = q->vertices[q->front];\n    q->front = (q->front + 1) % MAX_SIZE;\n    q->size--;\n    return vet;\n}\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\n    for (int i = 0; i < size; i++) {\n        if (visited[i] == vet)\n            return 1;\n    }\n    return 0;\n}\n\n/* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    Queue *queue = newQueue();\n    enqueue(queue, startVet);\n    visited[(*visitedSize)++] = startVet;\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (!isEmpty(queue)) {\n        Vertex *vet = dequeue(queue); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res[(*resSize)++] = vet;      // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        AdjListNode *node = findNode(graph, vet);\n        while (node != NULL) {\n            // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            if (!isVisited(visited, *visitedSize, node->vertex)) {\n                enqueue(queue, node->vertex);             // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n                visited[(*visitedSize)++] = node->vertex; // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n            }\n            node = node->next;\n        }\n    }\n    // \u91ca\u653e\u5185\u5b58\n    free(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\u8f85\u52a9\u51fd\u6570\"\"\"\n    res.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    # \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for adjVet in graph.adj_list[vet]:\n        if adjVet in visited:\n            continue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        # \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet)\n\ndef graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:\n    \"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386\"\"\"\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\n    res = []\n    # \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited = set[Vertex]()\n    dfs(graph, visited, res, start_vet)\n    return res\n
    graph_dfs.cpp
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList &graph, unordered_set<Vertex *> &visited, vector<Vertex *> &res, Vertex *vet) {\n    res.push_back(vet);   // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.emplace(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (Vertex *adjVet : graph.adjList[vet]) {\n        if (visited.count(adjVet))\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    vector<Vertex *> res;\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    unordered_set<Vertex *> visited;\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.java
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList graph, Set<Vertex> visited, List<Vertex> res, Vertex vet) {\n    res.add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (Vertex adjVet : graph.adjList.get(vet)) {\n        if (visited.contains(adjVet))\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = new ArrayList<>();\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    Set<Vertex> visited = new HashSet<>();\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.cs
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid DFS(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {\n    res.Add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.Add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    foreach (Vertex adjVet in graph.adjList[vet]) {\n        if (visited.Contains(adjVet)) {\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9                             \n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        DFS(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    HashSet<Vertex> visited = [];\n    DFS(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.go
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\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)\n    visited[vet] = struct{}{}\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for _, adjVet := range g.adjList[vet] {\n        _, isExist := visited[adjVet]\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        if !isExist {\n            dfs(g, visited, res, adjVet)\n        }\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    res := make([]Vertex, 0)\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited := make(map[Vertex]struct{})\n    dfs(g, visited, &res, startVet)\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n}\n
    graph_dfs.swift
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nfunc dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], vet: Vertex) {\n    res.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.insert(vet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for adjVet in graph.adjList[vet] ?? [] {\n        if visited.contains(adjVet) {\n            continue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph: graph, visited: &visited, res: &res, vet: adjVet)\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    var res: [Vertex] = []\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    var visited: Set<Vertex> = []\n    dfs(graph: graph, visited: &visited, res: &res, vet: startVet)\n    return res\n}\n
    graph_dfs.js
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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) {\n    res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (const adjVet of graph.adjList.get(vet)) {\n        if (visited.has(adjVet)) {\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited = new Set();\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.ts
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nfunction dfs(\n    graph: GraphAdjList,\n    visited: Set<Vertex>,\n    res: Vertex[],\n    vet: Vertex\n): void {\n    res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (const adjVet of graph.adjList.get(vet)) {\n        if (visited.has(adjVet)) {\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res: Vertex[] = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited: Set<Vertex> = new Set();\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.dart
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(\n  GraphAdjList graph,\n  Set<Vertex> visited,\n  List<Vertex> res,\n  Vertex vet,\n) {\n  res.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n  visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n  // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n  for (Vertex adjVet in graph.adjList[vet]!) {\n    if (visited.contains(adjVet)) {\n      continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n    }\n    // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n    dfs(graph, visited, res, adjVet);\n  }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nList<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {\n  // \u9876\u70b9\u904d\u5386\u5e8f\u5217\n  List<Vertex> res = [];\n  // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n  Set<Vertex> visited = {};\n  dfs(graph, visited, res, startVet);\n  return res;\n}\n
    graph_dfs.rs
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nfn dfs(graph: &GraphAdjList, visited: &mut HashSet<Vertex>, res: &mut Vec<Vertex>, vet: Vertex) {\n    res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.insert(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n                         // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    if let Some(adj_vets) = graph.adj_list.get(&vet) {\n        for &adj_vet in adj_vets {\n            if visited.contains(&adj_vet) {\n                continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n            dfs(graph, visited, res, adj_vet);\n        }\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    let mut res = vec![];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    let mut visited = HashSet::new();\n    dfs(&graph, &mut visited, &mut res, start_vet);\n\n    res\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\n    for (int i = 0; i < size; i++) {\n        if (res[i] == vet) {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList *graph, Vertex **res, int *resSize, Vertex *vet) {\n    // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    res[(*resSize)++] = vet;\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    AdjListNode *node = findNode(graph, vet);\n    while (node != NULL) {\n        // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        if (!isVisited(res, *resSize, node->vertex)) {\n            // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n            dfs(graph, res, resSize, node->vertex);\n        }\n        node = node->next;\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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) {\n    dfs(graph, res, resSize, startVet);\n}\n
    graph_dfs.zig
    [class]{}-[func]{dfs}\n\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\"\"\"\n\n    def __init__(self, w: int, v: int):\n        self.w = w  # \u7269\u54c1\u91cd\u91cf\n        self.v = v  # \u7269\u54c1\u4ef7\u503c\n\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\n    items = [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\n    items.sort(key=lambda item: item.v / item.w, reverse=True)\n    # \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    res = 0\n    for item in items:\n        if item.w <= cap:\n            # \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v\n            cap -= 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\n            res += (item.v / item.w) * cap\n            # \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break\n    return res\n
    fractional_knapsack.cpp
    /* \u7269\u54c1 */\nclass Item {\n  public:\n    int w; // \u7269\u54c1\u91cd\u91cf\n    int v; // \u7269\u54c1\u4ef7\u503c\n\n    Item(int w, int v) : w(w), v(v) {\n    }\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\n    vector<Item> items;\n    for (int i = 0; i < wgt.size(); i++) {\n        items.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\n    sort(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\n    double res = 0;\n    for (auto &item : items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (double)item.v / item.w * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.java
    /* \u7269\u54c1 */\nclass Item {\n    int w; // \u7269\u54c1\u91cd\u91cf\n    int v; // \u7269\u54c1\u4ef7\u503c\n\n    public Item(int w, int v) {\n        this.w = w;\n        this.v = v;\n    }\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\n    Item[] items = new Item[wgt.length];\n    for (int i = 0; i < wgt.length; i++) {\n        items[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\n    Arrays.sort(items, Comparator.comparingDouble(item -> -((double) item.v / item.w)));\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    double res = 0;\n    for (Item item : items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (double) item.v / item.w * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.cs
    /* \u7269\u54c1 */\nclass Item(int w, int v) {\n    public int w = w; // \u7269\u54c1\u91cd\u91cf\n    public int v = v; // \u7269\u54c1\u4ef7\u503c\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\n    Item[] items = new Item[wgt.Length];\n    for (int i = 0; i < wgt.Length; i++) {\n        items[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\n    Array.Sort(items, (x, y) => (y.v / y.w).CompareTo(x.v / x.w));\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    double res = 0;\n    foreach (Item item in items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (double)item.v / item.w * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.go
    /* \u7269\u54c1 */\ntype Item struct {\n    w int // \u7269\u54c1\u91cd\u91cf\n    v int // \u7269\u54c1\u4ef7\u503c\n}\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\n    items := make([]Item, len(wgt))\n    for i := 0; i < len(wgt); i++ {\n        items[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\n    sort.Slice(items, func(i, j int) bool {\n        return float64(items[i].v)/float64(items[i].w) > float64(items[j].v)/float64(items[j].w)\n    })\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    res := 0.0\n    for _, item := range items {\n        if item.w <= cap {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += float64(item.v)\n            cap -= 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\n            res += float64(item.v) / float64(item.w) * float64(cap)\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break\n        }\n    }\n    return res\n}\n
    fractional_knapsack.swift
    /* \u7269\u54c1 */\nclass Item {\n    var w: Int // \u7269\u54c1\u91cd\u91cf\n    var v: Int // \u7269\u54c1\u4ef7\u503c\n\n    init(w: Int, v: Int) {\n        self.w = w\n        self.v = v\n    }\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\n    var 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\n    items.sort(by: { -(Double($0.v) / Double($0.w)) < -(Double($1.v) / Double($1.w)) })\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    var res = 0.0\n    var cap = cap\n    for item in items {\n        if item.w <= cap {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += Double(item.v)\n            cap -= 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\n            res += Double(item.v) / Double(item.w) * Double(cap)\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break\n        }\n    }\n    return res\n}\n
    fractional_knapsack.js
    /* \u7269\u54c1 */\nclass Item {\n    constructor(w, v) {\n        this.w = w; // \u7269\u54c1\u91cd\u91cf\n        this.v = v; // \u7269\u54c1\u4ef7\u503c\n    }\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\n    const 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\n    items.sort((a, b) => b.v / b.w - a.v / a.w);\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    let res = 0;\n    for (const item of items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (item.v / item.w) * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.ts
    /* \u7269\u54c1 */\nclass Item {\n    w: number; // \u7269\u54c1\u91cd\u91cf\n    v: number; // \u7269\u54c1\u4ef7\u503c\n\n    constructor(w: number, v: number) {\n        this.w = w;\n        this.v = v;\n    }\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\n    const 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\n    items.sort((a, b) => b.v / b.w - a.v / a.w);\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    let res = 0;\n    for (const item of items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (item.v / item.w) * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.dart
    /* \u7269\u54c1 */\nclass Item {\n  int w; // \u7269\u54c1\u91cd\u91cf\n  int v; // \u7269\u54c1\u4ef7\u503c\n\n  Item(this.w, this.v);\n}\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\n  List<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\n  items.sort((a, b) => (b.v / b.w).compareTo(a.v / a.w));\n  // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n  double res = 0;\n  for (Item item in items) {\n    if (item.w <= cap) {\n      // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n      res += item.v;\n      cap -= 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\n      res += item.v / item.w * cap;\n      // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n      break;\n    }\n  }\n  return res;\n}\n
    fractional_knapsack.rs
    /* \u7269\u54c1 */\nstruct Item {\n    w: i32, // \u7269\u54c1\u91cd\u91cf\n    v: i32, // \u7269\u54c1\u4ef7\u503c\n}\n\nimpl Item {\n    fn new(w: i32, v: i32) -> Self {\n        Self { w, v }\n    }\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\n    let 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\n    items.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\n    let mut res = 0.0;\n    for item in &items {\n        if item.w <= cap {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v as f64;\n            cap -= 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\n            res += 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\n            break;\n        }\n    }\n    res\n}\n
    fractional_knapsack.c
    /* \u7269\u54c1 */\ntypedef struct {\n    int w; // \u7269\u54c1\u91cd\u91cf\n    int v; // \u7269\u54c1\u4ef7\u503c\n} Item;\n\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\n    Item *items = malloc(sizeof(Item) * itemCount);\n    for (int i = 0; i < itemCount; i++) {\n        items[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\n    qsort(items, (size_t)itemCount, sizeof(Item), sortByValueDensity);\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    float res = 0.0;\n    for (int i = 0; i < itemCount; i++) {\n        if (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\n            res += items[i].v;\n            cap -= 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\n            res += (float)cap / items[i].w * items[i].v;\n            cap = 0;\n            break;\n        }\n    }\n    free(items);\n    return res;\n}\n
    fractional_knapsack.zig
    [class]{Item}-[func]{}\n\n[class]{}-[func]{fractionalKnapsack}\n

    \u9664\u6392\u5e8f\u4e4b\u5916\uff0c\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\u56f4\u6210\u7684\u6700\u5927\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\uff0c\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\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\n    i = len(coins) - 1\n    count = 0\n    # \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while amt > 0:\n        # \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while i > 0 and coins[i] > amt:\n            i -= 1\n        # \u9009\u62e9 coins[i]\n        amt -= coins[i]\n        count += 1\n    # \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    int i = coins.size() - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    int i = coins.length - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    int i = coins.Length - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    i := len(coins) - 1\n    count := 0\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    for amt > 0 {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        for i > 0 && coins[i] > amt {\n            i--\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i]\n        count++\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    if amt != 0 {\n        return -1\n    }\n    return 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\n    var i = coins.count - 1\n    var count = 0\n    var amt = amt\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while amt > 0 {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while i > 0 && coins[i] > amt {\n            i -= 1\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i]\n        count += 1\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    let i = coins.length - 1;\n    let count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    let i = coins.length - 1;\n    let count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n  int i = coins.length - 1;\n  int count = 0;\n  // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n  while (amt > 0) {\n    // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n    while (i > 0 && coins[i] > amt) {\n      i--;\n    }\n    // \u9009\u62e9 coins[i]\n    amt -= coins[i];\n    count++;\n  }\n  // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n  return 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\n    let mut i = coins.len() - 1;\n    let mut count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while amt > 0 {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while i > 0 && coins[i] > amt {\n            i -= 1;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count += 1;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    if amt == 0 {\n        count\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\n    int i = size - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return amt == 0 ? count : -1;\n}\n
    coin_change_greedy.zig
    [class]{}-[func]{coinChangeGreedy}\n

    \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\u3002

    "},{"location":"chapter_greedy/greedy_algorithm/#1511","title":"15.1.1 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5\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)\\) \u964d\u4f4e\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\u7b97\u6cd5\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, D. A polynomial-time algorithm for the change-making problem[J]. Operations Research Letters, 2005, 33(3): 231-234.

    "},{"location":"chapter_greedy/greedy_algorithm/#1513","title":"15.1.3 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5\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\u7b97\u6cd5\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\uff0c\u4f7f\u5176\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\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\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    i, j = 0, len(ht) - 1\n    # \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    res = 0\n    # \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while i < j:\n        # \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        cap = min(ht[i], ht[j]) * (j - i)\n        res = max(res, cap)\n        # \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j]:\n            i += 1\n        else:\n            j -= 1\n    return res\n
    max_capacity.cpp
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(vector<int> &ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0, j = ht.size() - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int cap = min(ht[i], ht[j]) * (j - i);\n        res = max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return res;\n}\n
    max_capacity.java
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int[] ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0, j = ht.length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int cap = Math.min(ht[i], ht[j]) * (j - i);\n        res = Math.max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return res;\n}\n
    max_capacity.cs
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint MaxCapacity(int[] ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0, j = ht.Length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int cap = Math.Min(ht[i], ht[j]) * (j - i);\n        res = Math.Max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return res;\n}\n
    max_capacity.go
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht []int) int {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    i, j := 0, len(ht)-1\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    res := 0\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    for i < j {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        capacity := int(math.Min(float64(ht[i]), float64(ht[j]))) * (j - i)\n        res = int(math.Max(float64(res), float64(capacity)))\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j] {\n            i++\n        } else {\n            j--\n        }\n    }\n    return res\n}\n
    max_capacity.swift
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht: [Int]) -> Int {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    var i = 0, j = ht.count - 1\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    var res = 0\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while i < j {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        let cap = min(ht[i], ht[j]) * (j - i)\n        res = max(res, cap)\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j] {\n            i += 1\n        } else {\n            j -= 1\n        }\n    }\n    return res\n}\n
    max_capacity.js
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    let i = 0,\n        j = ht.length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    let res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        const cap = Math.min(ht[i], ht[j]) * (j - i);\n        res = Math.max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i += 1;\n        } else {\n            j -= 1;\n        }\n    }\n    return res;\n}\n
    max_capacity.ts
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht: number[]): number {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    let i = 0,\n        j = ht.length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    let res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        const cap: number = Math.min(ht[i], ht[j]) * (j - i);\n        res = Math.max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i += 1;\n        } else {\n            j -= 1;\n        }\n    }\n    return res;\n}\n
    max_capacity.dart
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(List<int> ht) {\n  // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n  int i = 0, j = ht.length - 1;\n  // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n  int res = 0;\n  // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n  while (i < j) {\n    // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n    int cap = min(ht[i], ht[j]) * (j - i);\n    res = max(res, cap);\n    // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n    if (ht[i] < ht[j]) {\n      i++;\n    } else {\n      j--;\n    }\n  }\n  return 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\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    let mut i = 0;\n    let mut j = ht.len() - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    let mut res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while i < j {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        let cap = std::cmp::min(ht[i], ht[j]) * (j - i) as i32;\n        res = std::cmp::max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j] {\n            i += 1;\n        } else {\n            j -= 1;\n        }\n    }\n    res\n}\n
    max_capacity.c
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int ht[], int htLength) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0;\n    int j = htLength - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int capacity = myMin(ht[i], ht[j]) * (j - i);\n        res = myMax(res, capacity);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return 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\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\n    if n <= 3:\n        return 1 * (n - 1)\n    # \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    a, b = n // 3, n % 3\n    if b == 1:\n        # \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return int(math.pow(3, a - 1)) * 2 * 2\n    if b == 2:\n        # \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return int(math.pow(3, a)) * 2\n    # \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return (int)pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return (int)pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return (int) Math.pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return (int) Math.pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return (int)Math.Pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return (int)Math.Pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (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\n    if n <= 3 {\n        return 1 * (n - 1)\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    a := n / 3\n    b := n % 3\n    if b == 1 {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return int(math.Pow(3, float64(a-1))) * 2 * 2\n    }\n    if b == 2 {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return int(math.Pow(3, float64(a))) * 2\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if n <= 3 {\n        return 1 * (n - 1)\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a = n / 3\n    let b = n % 3\n    if b == 1 {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return pow(3, a - 1) * 2 * 2\n    }\n    if b == 2 {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return pow(3, a) * 2\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a = Math.floor(n / 3);\n    let b = n % 3;\n    if (b === 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return Math.pow(3, a - 1) * 2 * 2;\n    }\n    if (b === 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return Math.pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a: number = Math.floor(n / 3);\n    let b: number = n % 3;\n    if (b === 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return Math.pow(3, a - 1) * 2 * 2;\n    }\n    if (b === 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return Math.pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n  if (n <= 3) {\n    return 1 * (n - 1);\n  }\n  // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n  int a = n ~/ 3;\n  int b = n % 3;\n  if (b == 1) {\n    // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n    return (pow(3, a - 1) * 2 * 2).toInt();\n  }\n  if (b == 2) {\n    // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (pow(3, a) * 2).toInt();\n  }\n  // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n  return 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\n    if n <= 3 {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a = n / 3;\n    let b = n % 3;\n    if b == 1 {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        3_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\n        3_i32.pow(a as u32) * 2\n    } else {\n        // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        3_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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\uff0c\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\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash += ord(c)\n    return hash % modulus\n\ndef mul_hash(key: str) -> int:\n    \"\"\"\u4e58\u6cd5\u54c8\u5e0c\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash = 31 * hash + ord(c)\n    return hash % modulus\n\ndef xor_hash(key: str) -> int:\n    \"\"\"\u5f02\u6216\u54c8\u5e0c\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash ^= ord(c)\n    return hash % modulus\n\ndef rot_hash(key: str) -> int:\n    \"\"\"\u65cb\u8f6c\u54c8\u5e0c\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash = (hash << 4) ^ (hash >> 28) ^ ord(c)\n    return hash % modulus\n
    simple_hash.cpp
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(string key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash = (hash + (int)c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(string key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash = (31 * hash + (int)c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(string key) {\n    int hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash ^= (int)c;\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(string key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ (int)c) % MODULUS;\n    }\n    return (int)hash;\n}\n
    simple_hash.java
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\n    long hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash = (hash + (int) c) % MODULUS;\n    }\n    return (int) hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\n    long hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash = (31 * hash + (int) c) % MODULUS;\n    }\n    return (int) hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\n    int hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash ^= (int) c;\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\n    long hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ (int) c) % MODULUS;\n    }\n    return (int) hash;\n}\n
    simple_hash.cs
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint AddHash(string key) {\n    long hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash = (hash + c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint MulHash(string key) {\n    long hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash = (31 * hash + c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint XorHash(string key) {\n    int hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash ^= c;\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint RotHash(string key) {\n    long hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c) % MODULUS;\n    }\n    return (int)hash;\n}\n
    simple_hash.go
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key string) int {\n    var hash int64\n    var modulus int64\n\n    modulus = 1000000007\n    for _, b := range []byte(key) {\n        hash = (hash + int64(b)) % modulus\n    }\n    return int(hash)\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key string) int {\n    var hash int64\n    var modulus int64\n\n    modulus = 1000000007\n    for _, b := range []byte(key) {\n        hash = (31*hash + int64(b)) % modulus\n    }\n    return int(hash)\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key string) int {\n    hash := 0\n    modulus := 1000000007\n    for _, b := range []byte(key) {\n        fmt.Println(int(b))\n        hash ^= int(b)\n        hash = (31*hash + int(b)) % modulus\n    }\n    return hash & modulus\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key string) int {\n    var hash int64\n    var modulus int64\n\n    modulus = 1000000007\n    for _, b := range []byte(key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ int64(b)) % modulus\n    }\n    return int(hash)\n}\n
    simple_hash.swift
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash = (hash + Int(scalar.value)) % MODULUS\n        }\n    }\n    return hash\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash = (31 * hash + Int(scalar.value)) % MODULUS\n        }\n    }\n    return hash\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash ^= Int(scalar.value)\n        }\n    }\n    return hash & MODULUS\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash = ((hash << 4) ^ (hash >> 28) ^ Int(scalar.value)) % MODULUS\n        }\n    }\n    return hash\n}\n
    simple_hash.js
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash ^= c.charCodeAt(0);\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n
    simple_hash.ts
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash ^= c.charCodeAt(0);\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n
    simple_hash.dart
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash = (hash + key.codeUnitAt(i)) % MODULUS;\n  }\n  return hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash = (31 * hash + key.codeUnitAt(i)) % MODULUS;\n  }\n  return hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash ^= key.codeUnitAt(i);\n  }\n  return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash = ((hash << 4) ^ (hash >> 28) ^ key.codeUnitAt(i)) % MODULUS;\n  }\n  return hash;\n}\n
    simple_hash.rs
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfn add_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash = (hash + c as i64) % MODULUS;\n    }\n\n    hash as i32\n} \n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfn mul_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash = (31 * hash + c as i64) % MODULUS;\n    }\n\n    hash as i32\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfn xor_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash ^= c as i64;\n    }\n\n    (hash & MODULUS) as i32\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfn rot_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c as i64) % MODULUS;\n    }\n\n    hash as i32\n}\n
    simple_hash.c
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(char *key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (int i = 0; i < strlen(key); i++) {\n        hash = (hash + (unsigned char)key[i]) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(char *key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (int i = 0; i < strlen(key); i++) {\n        hash = (31 * hash + (unsigned char)key[i]) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(char *key) {\n    int hash = 0;\n    const int MODULUS = 1000000007;\n\n    for (int i = 0; i < strlen(key); i++) {\n        hash ^= (unsigned char)key[i];\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(char *key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (int i = 0; i < strlen(key); i++) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ (unsigned char)key[i]) % MODULUS;\n    }\n\n    return (int)hash;\n}\n
    simple_hash.zig
    [class]{}-[func]{addHash}\n\n[class]{}-[func]{mulHash}\n\n[class]{}-[func]{xorHash}\n\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 \u548c SHA-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 bit 160 bit 256/512 bit 224/256/384/512 bit \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\n\nbol = True\nhash_bol = hash(bol)\n# \u5e03\u5c14\u91cf True \u7684\u54c8\u5e0c\u503c\u4e3a 1\n\ndec = 3.14159\nhash_dec = hash(dec)\n# \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 326484311674566659\n\nstr = \"Hello \u7b97\u6cd5\"\nhash_str = hash(str)\n# \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 4617003410720528961\n\ntup = (12836, \"\u5c0f\u54c8\")\nhash_tup = hash(tup)\n# \u5143\u7ec4 (12836, '\u5c0f\u54c8') \u7684\u54c8\u5e0c\u503c\u4e3a 1029005403108185979\n\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\n\nbool bol = true;\nsize_t hashBol = hash<bool>()(bol);\n// \u5e03\u5c14\u91cf 1 \u7684\u54c8\u5e0c\u503c\u4e3a 1\n\ndouble dec = 3.14159;\nsize_t hashDec = hash<double>()(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 4614256650576692846\n\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\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\n\nboolean bol = true;\nint hashBol = Boolean.hashCode(bol);\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\n\ndouble dec = 3.14159;\nint hashDec = Double.hashCode(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729\n\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -727081396\n\nObject[] arr = { 12836, \"\u5c0f\u54c8\" };\nint hashTup = Arrays.hashCode(arr);\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 1151158\n\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;\n\nbool bol = true;\nint hashBol = bol.GetHashCode();\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1;\n\ndouble dec = 3.14159;\nint hashDec = dec.GetHashCode();\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729;\n\nstring str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.GetHashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -586107568;\n\nobject[] arr = [12836, \"\u5c0f\u54c8\"];\nint hashTup = arr.GetHashCode();\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 42931033;\n\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\n\nlet bol = true\nlet hashBol = bol.hashValue\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a -4431640247352757451\n\nlet dec = 3.14159\nlet hashDec = dec.hashValue\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -2465384235396674631\n\nlet str = \"Hello \u7b97\u6cd5\"\nlet hashStr = str.hashValue\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -7850626797806988787\n\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\n\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\n\nbool bol = true;\nint hashBol = bol.hashCode;\n// \u5e03\u5c14\u503c true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\n\ndouble dec = 3.14159;\nint hashDec = dec.hashCode;\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 2570631074981783\n\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode;\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 468167534\n\nList arr = [12836, \"\u5c0f\u54c8\"];\nint hashArr = arr.hashCode;\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 976512528\n\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};\n\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\n\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\n\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\n\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\n\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\n\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\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6bcf\u5f53\u9047\u5230\u54c8\u5e0c\u51b2\u7a81\u65f6\uff0c\u6211\u4eec\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\uff1a\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\uff1a\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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\n        self.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\n        self.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        self.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\n        self.buckets = [[] for _ in range(self.capacity)]  # \u6876\u6570\u7ec4\n\n    def hash_func(self, key: int) -> int:\n        \"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\n        return key % self.capacity\n\n    def load_factor(self) -> float:\n        \"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\n        return self.size / self.capacity\n\n    def get(self, key: int) -> str | None:\n        \"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n        index = self.hash_func(key)\n        bucket = self.buckets[index]\n        # \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for pair in bucket:\n            if pair.key == key:\n                return pair.val\n        # \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de None\n        return None\n\n    def 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\n        if self.load_factor() > self.load_thres:\n            self.extend()\n        index = self.hash_func(key)\n        bucket = self.buckets[index]\n        # \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for pair in bucket:\n            if pair.key == key:\n                pair.val = val\n                return\n        # \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        pair = Pair(key, val)\n        bucket.append(pair)\n        self.size += 1\n\n    def remove(self, key: int):\n        \"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n        index = self.hash_func(key)\n        bucket = self.buckets[index]\n        # \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for pair in bucket:\n            if pair.key == key:\n                bucket.remove(pair)\n                self.size -= 1\n                break\n\n    def extend(self):\n        \"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n        # \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        buckets = self.buckets\n        # \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio\n        self.buckets = [[] for _ in range(self.capacity)]\n        self.size = 0\n        # \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for bucket in buckets:\n            for pair in bucket:\n                self.put(pair.key, pair.val)\n\n    def print(self):\n        \"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\n        for bucket in self.buckets:\n            res = []\n            for pair in bucket:\n                res.append(str(pair.key) + \" -> \" + pair.val)\n            print(res)\n
    hash_map_chaining.cpp
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n  private:\n    int size;                       // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity;                   // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres;               // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio;                // \u6269\u5bb9\u500d\u6570\n    vector<vector<Pair *>> buckets; // \u6876\u6570\u7ec4\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3.0), extendRatio(2) {\n        buckets.resize(capacity);\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~HashMapChaining() {\n        for (auto &bucket : buckets) {\n            for (Pair *pair : bucket) {\n                // \u91ca\u653e\u5185\u5b58\n                delete pair;\n            }\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double loadFactor() {\n        return (double)size / (double)capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    string get(int key) {\n        int index = hashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (Pair *pair : buckets[index]) {\n            if (pair->key == key) {\n                return pair->val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n        return \"\";\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        int index = hashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for (Pair *pair : buckets[index]) {\n            if (pair->key == key) {\n                pair->val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        buckets[index].push_back(new Pair(key, val));\n        size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        int index = hashFunc(key);\n        auto &bucket = buckets[index];\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (int i = 0; i < bucket.size(); i++) {\n            if (bucket[i]->key == key) {\n                Pair *tmp = bucket[i];\n                bucket.erase(bucket.begin() + i); // \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n                delete tmp;                       // \u91ca\u653e\u5185\u5b58\n                size--;\n                return;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        vector<vector<Pair *>> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets.clear();\n        buckets.resize(capacity);\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (auto &bucket : bucketsTmp) {\n            for (Pair *pair : bucket) {\n                put(pair->key, pair->val);\n                // \u91ca\u653e\u5185\u5b58\n                delete pair;\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (auto &bucket : buckets) {\n            cout << \"[\";\n            for (Pair *pair : bucket) {\n                cout << pair->key << \" -> \" << pair->val << \", \";\n            }\n            cout << \"]\\n\";\n        }\n    }\n};\n
    hash_map_chaining.java
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n    int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio; // \u6269\u5bb9\u500d\u6570\n    List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapChaining() {\n        size = 0;\n        capacity = 4;\n        loadThres = 2.0 / 3.0;\n        extendRatio = 2;\n        buckets = new ArrayList<>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.add(new ArrayList<>());\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double loadFactor() {\n        return (double) size / capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    String get(int key) {\n        int index = hashFunc(key);\n        List<Pair> bucket = buckets.get(index);\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (Pair pair : bucket) {\n            if (pair.key == key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, String val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        int index = hashFunc(key);\n        List<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\n        for (Pair pair : bucket) {\n            if (pair.key == key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        Pair pair = new Pair(key, val);\n        bucket.add(pair);\n        size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        int index = hashFunc(key);\n        List<Pair> bucket = buckets.get(index);\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (Pair pair : bucket) {\n            if (pair.key == key) {\n                bucket.remove(pair);\n                size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        List<List<Pair>> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new ArrayList<>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.add(new ArrayList<>());\n        }\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (List<Pair> bucket : bucketsTmp) {\n            for (Pair pair : bucket) {\n                put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (List<Pair> bucket : buckets) {\n            List<String> res = new ArrayList<>();\n            for (Pair pair : bucket) {\n                res.add(pair.key + \" -> \" + pair.val);\n            }\n            System.out.println(res);\n        }\n    }\n}\n
    hash_map_chaining.cs
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n    int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio; // \u6269\u5bb9\u500d\u6570\n    List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapChaining() {\n        size = 0;\n        capacity = 4;\n        loadThres = 2.0 / 3.0;\n        extendRatio = 2;\n        buckets = new List<List<Pair>>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.Add([]);\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int HashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double LoadFactor() {\n        return (double)size / capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public string? Get(int key) {\n        int index = HashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        foreach (Pair pair in buckets[index]) {\n            if (pair.key == key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void Put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (LoadFactor() > loadThres) {\n            Extend();\n        }\n        int index = HashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        foreach (Pair pair in buckets[index]) {\n            if (pair.key == key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        buckets[index].Add(new Pair(key, val));\n        size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void Remove(int key) {\n        int index = HashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        foreach (Pair pair in buckets[index].ToList()) {\n            if (pair.key == key) {\n                buckets[index].Remove(pair);\n                size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void Extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        List<List<Pair>> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new List<List<Pair>>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.Add([]);\n        }\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        foreach (List<Pair> bucket in bucketsTmp) {\n            foreach (Pair pair in bucket) {\n                Put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void Print() {\n        foreach (List<Pair> bucket in buckets) {\n            List<string> res = [];\n            foreach (Pair pair in bucket) {\n                res.Add(pair.key + \" -> \" + pair.val);\n            }\n            foreach (string kv in res) {\n                Console.WriteLine(kv);\n            }\n        }\n    }\n}\n
    hash_map_chaining.go
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntype hashMapChaining struct {\n    size        int      // \u952e\u503c\u5bf9\u6570\u91cf\n    capacity    int      // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    loadThres   float64  // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    extendRatio int      // \u6269\u5bb9\u500d\u6570\n    buckets     [][]pair // \u6876\u6570\u7ec4\n}\n\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapChaining() *hashMapChaining {\n    buckets := make([][]pair, 4)\n    for i := 0; i < 4; i++ {\n        buckets[i] = make([]pair, 0)\n    }\n    return &hashMapChaining{\n        size:        0,\n        capacity:    4,\n        loadThres:   2.0 / 3.0,\n        extendRatio: 2,\n        buckets:     buckets,\n    }\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapChaining) hashFunc(key int) int {\n    return key % m.capacity\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapChaining) loadFactor() float64 {\n    return float64(m.size) / float64(m.capacity)\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapChaining) get(key int) string {\n    idx := m.hashFunc(key)\n    bucket := m.buckets[idx]\n    // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    for _, p := range bucket {\n        if p.key == key {\n            return p.val\n        }\n    }\n    // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n    return \"\"\n}\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\n    if m.loadFactor() > m.loadThres {\n        m.extend()\n    }\n    idx := m.hashFunc(key)\n    // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n    for i := range m.buckets[idx] {\n        if m.buckets[idx][i].key == key {\n            m.buckets[idx][i].val = val\n            return\n        }\n    }\n    // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n    p := pair{\n        key: key,\n        val: val,\n    }\n    m.buckets[idx] = append(m.buckets[idx], p)\n    m.size += 1\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapChaining) remove(key int) {\n    idx := m.hashFunc(key)\n    // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n    for i, p := range m.buckets[idx] {\n        if p.key == key {\n            // \u5207\u7247\u5220\u9664\n            m.buckets[idx] = append(m.buckets[idx][:i], m.buckets[idx][i+1:]...)\n            m.size -= 1\n            break\n        }\n    }\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    tmpBuckets := make([][]pair, len(m.buckets))\n    for i := 0; i < len(m.buckets); i++ {\n        tmpBuckets[i] = make([]pair, len(m.buckets[i]))\n        copy(tmpBuckets[i], m.buckets[i])\n    }\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    m.capacity *= m.extendRatio\n    m.buckets = make([][]pair, m.capacity)\n    for i := 0; i < m.capacity; i++ {\n        m.buckets[i] = make([]pair, 0)\n    }\n    m.size = 0\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for _, bucket := range tmpBuckets {\n        for _, p := range bucket {\n            m.put(p.key, p.val)\n        }\n    }\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) print() {\n    var builder strings.Builder\n\n    for _, bucket := range m.buckets {\n        builder.WriteString(\"[\")\n        for _, p := range bucket {\n            builder.WriteString(strconv.Itoa(p.key) + \" -> \" + p.val + \" \")\n        }\n        builder.WriteString(\"]\")\n        fmt.Println(builder.String())\n        builder.Reset()\n    }\n}\n
    hash_map_chaining.swift
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n    var size: Int // \u952e\u503c\u5bf9\u6570\u91cf\n    var capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    var loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    var extendRatio: Int // \u6269\u5bb9\u500d\u6570\n    var buckets: [[Pair]] // \u6876\u6570\u7ec4\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init() {\n        size = 0\n        capacity = 4\n        loadThres = 2.0 / 3.0\n        extendRatio = 2\n        buckets = Array(repeating: [], count: capacity)\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    func hashFunc(key: Int) -> Int {\n        key % capacity\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    func loadFactor() -> Double {\n        Double(size / capacity)\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    func get(key: Int) -> String? {\n        let index = hashFunc(key: key)\n        let bucket = buckets[index]\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for pair in bucket {\n            if pair.key == key {\n                return pair.val\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de nil\n        return nil\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    func put(key: Int, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if loadFactor() > loadThres {\n            extend()\n        }\n        let index = hashFunc(key: key)\n        let bucket = buckets[index]\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for pair in bucket {\n            if pair.key == key {\n                pair.val = val\n                return\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        let pair = Pair(key: key, val: val)\n        buckets[index].append(pair)\n        size += 1\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    func remove(key: Int) {\n        let index = hashFunc(key: key)\n        let bucket = buckets[index]\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (pairIndex, pair) in bucket.enumerated() {\n            if pair.key == key {\n                buckets[index].remove(at: pairIndex)\n            }\n        }\n        size -= 1\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    func extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let bucketsTmp = buckets\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio\n        buckets = Array(repeating: [], count: capacity)\n        size = 0\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for bucket in bucketsTmp {\n            for pair in bucket {\n                put(key: pair.key, val: pair.val)\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    func print() {\n        for bucket in buckets {\n            let res = bucket.map { \"\\($0.key) -> \\($0.val)\" }\n            Swift.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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#size = 0;\n        this.#capacity = 4;\n        this.#loadThres = 2.0 / 3.0;\n        this.#extendRatio = 2;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key) {\n        return key % this.#capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    #loadFactor() {\n        return this.#size / this.#capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key) {\n        const index = this.#hashFunc(key);\n        const bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key, val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.#loadFactor() > this.#loadThres) {\n            this.#extend();\n        }\n        const index = this.#hashFunc(key);\n        const 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\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        const pair = new Pair(key, val);\n        bucket.push(pair);\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key) {\n        const index = this.#hashFunc(key);\n        let bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (let i = 0; i < bucket.length; i++) {\n            if (bucket[i].key === key) {\n                bucket.splice(i, 1);\n                this.#size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    #extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.#buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.#capacity *= this.#extendRatio;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n        this.#size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const bucket of bucketsTmp) {\n            for (const pair of bucket) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print() {\n        for (const bucket of this.#buckets) {\n            let res = [];\n            for (const pair of bucket) {\n                res.push(pair.key + ' -> ' + pair.val);\n            }\n            console.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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#size = 0;\n        this.#capacity = 4;\n        this.#loadThres = 2.0 / 3.0;\n        this.#extendRatio = 2;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key: number): number {\n        return key % this.#capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    #loadFactor(): number {\n        return this.#size / this.#capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key: number): string | null {\n        const index = this.#hashFunc(key);\n        const bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key: number, val: string): void {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.#loadFactor() > this.#loadThres) {\n            this.#extend();\n        }\n        const index = this.#hashFunc(key);\n        const 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\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        const pair = new Pair(key, val);\n        bucket.push(pair);\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key: number): void {\n        const index = this.#hashFunc(key);\n        let bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (let i = 0; i < bucket.length; i++) {\n            if (bucket[i].key === key) {\n                bucket.splice(i, 1);\n                this.#size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    #extend(): void {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.#buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.#capacity *= this.#extendRatio;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n        this.#size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const bucket of bucketsTmp) {\n            for (const pair of bucket) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print(): void {\n        for (const bucket of this.#buckets) {\n            let res = [];\n            for (const pair of bucket) {\n                res.push(pair.key + ' -> ' + pair.val);\n            }\n            console.log(res);\n        }\n    }\n}\n
    hash_map_chaining.dart
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n  late int size; // \u952e\u503c\u5bf9\u6570\u91cf\n  late int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n  late double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n  late int extendRatio; // \u6269\u5bb9\u500d\u6570\n  late List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  HashMapChaining() {\n    size = 0;\n    capacity = 4;\n    loadThres = 2.0 / 3.0;\n    extendRatio = 2;\n    buckets = List.generate(capacity, (_) => []);\n  }\n\n  /* \u54c8\u5e0c\u51fd\u6570 */\n  int hashFunc(int key) {\n    return key % capacity;\n  }\n\n  /* \u8d1f\u8f7d\u56e0\u5b50 */\n  double loadFactor() {\n    return size / capacity;\n  }\n\n  /* \u67e5\u8be2\u64cd\u4f5c */\n  String? get(int key) {\n    int index = hashFunc(key);\n    List<Pair> bucket = buckets[index];\n    // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    for (Pair pair in bucket) {\n      if (pair.key == key) {\n        return pair.val;\n      }\n    }\n    // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n    return null;\n  }\n\n  /* \u6dfb\u52a0\u64cd\u4f5c */\n  void put(int key, String val) {\n    // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n    if (loadFactor() > loadThres) {\n      extend();\n    }\n    int index = hashFunc(key);\n    List<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\n    for (Pair pair in bucket) {\n      if (pair.key == key) {\n        pair.val = val;\n        return;\n      }\n    }\n    // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n    Pair pair = Pair(key, val);\n    bucket.add(pair);\n    size++;\n  }\n\n  /* \u5220\u9664\u64cd\u4f5c */\n  void remove(int key) {\n    int index = hashFunc(key);\n    List<Pair> bucket = buckets[index];\n    // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n    for (Pair pair in bucket) {\n      if (pair.key == key) {\n        bucket.remove(pair);\n        size--;\n        break;\n      }\n    }\n  }\n\n  /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n  void extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    List<List<Pair>> bucketsTmp = buckets;\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    capacity *= extendRatio;\n    buckets = List.generate(capacity, (_) => []);\n    size = 0;\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for (List<Pair> bucket in bucketsTmp) {\n      for (Pair pair in bucket) {\n        put(pair.key, pair.val);\n      }\n    }\n  }\n\n  /* \u6253\u5370\u54c8\u5e0c\u8868 */\n  void printHashMap() {\n    for (List<Pair> bucket in buckets) {\n      List<String> res = [];\n      for (Pair pair in bucket) {\n        res.add(\"${pair.key} -> ${pair.val}\");\n      }\n      print(res);\n    }\n  }\n}\n
    hash_map_chaining.rs
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapChaining {\n    size: i32,\n    capacity: i32,\n    load_thres: f32,\n    extend_ratio: i32,\n    buckets: Vec<Vec<Pair>>,\n}\n\nimpl HashMapChaining {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new() -> Self {\n        Self {\n            size: 0,\n            capacity: 4,\n            load_thres: 2.0 / 3.0,\n            extend_ratio: 2,\n            buckets: vec![vec![]; 4],\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    fn hash_func(&self, key: i32) -> usize {\n        key as usize % self.capacity as usize\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    fn load_factor(&self) -> f32 {\n        self.size as f32 / self.capacity as f32\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    fn remove(&mut self, key: i32) -> Option<String> {\n        let index = self.hash_func(key);\n        let bucket = &mut self.buckets[index];\n\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for i in 0..bucket.len() {\n            if bucket[i].key == key {\n                let pair = bucket.remove(i);\n                self.size -= 1;\n                return Some(pair.val);\n            }\n        }\n\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de None\n        None\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    fn extend(&mut self) {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let buckets_tmp = std::mem::replace(&mut self.buckets, vec![]);\n\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio;\n        self.buckets = vec![Vec::new(); self.capacity as usize];\n        self.size = 0;\n\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for bucket in buckets_tmp {\n            for pair in bucket {\n                self.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    fn print(&self) {\n        for bucket in &self.buckets {\n            let mut res = Vec::new();\n            for pair in bucket {\n                res.push(format!(\"{} -> {}\", pair.key, pair.val));\n            }\n            println!(\"{:?}\", res);\n        }\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    fn put(&mut self, key: i32, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if self.load_factor() > self.load_thres {\n            self.extend();\n        }\n\n        let index = self.hash_func(key);\n        let bucket = &mut self.buckets[index];\n\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for pair in bucket {\n            if pair.key == key {\n                pair.val = val.clone();\n                return;\n            }\n        }\n        let bucket = &mut self.buckets[index];\n\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        let pair = Pair {\n            key,\n            val: val.clone(),\n        };\n        bucket.push(pair);\n        self.size += 1;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    fn get(&self, key: i32) -> Option<&str> {\n        let index = self.hash_func(key);\n        let bucket = &self.buckets[index];\n\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for pair in bucket {\n            if pair.key == key {\n                return Some(&pair.val);\n            }\n        }\n\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de None\n        None\n    }\n}\n
    hash_map_chaining.c
    /* \u94fe\u8868\u8282\u70b9 */\ntypedef struct Node {\n    Pair *pair;\n    struct Node *next;\n} Node;\n\n/* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\n    int size;         // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio;  // \u6269\u5bb9\u500d\u6570\n    Node **buckets;   // \u6876\u6570\u7ec4\n} HashMapChaining;\n\n/* \u6784\u9020\u51fd\u6570 */\nHashMapChaining *newHashMapChaining() {\n    HashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));\n    hashMap->size = 0;\n    hashMap->capacity = 4;\n    hashMap->loadThres = 2.0 / 3.0;\n    hashMap->extendRatio = 2;\n    hashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\n    for (int i = 0; i < hashMap->capacity; i++) {\n        hashMap->buckets[i] = NULL;\n    }\n    return hashMap;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapChaining(HashMapChaining *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Node *cur = hashMap->buckets[i];\n        while (cur) {\n            Node *tmp = cur;\n            cur = cur->next;\n            free(tmp->pair);\n            free(tmp);\n        }\n    }\n    free(hashMap->buckets);\n    free(hashMap);\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapChaining *hashMap, int key) {\n    return key % hashMap->capacity;\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapChaining *hashMap) {\n    return (double)hashMap->size / (double)hashMap->capacity;\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapChaining *hashMap, int key) {\n    int index = hashFunc(hashMap, key);\n    // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    Node *cur = hashMap->buckets[index];\n    while (cur) {\n        if (cur->pair->key == key) {\n            return cur->pair->val;\n        }\n        cur = cur->next;\n    }\n    return \"\"; // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n}\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\n    if (loadFactor(hashMap) > hashMap->loadThres) {\n        extend(hashMap);\n    }\n    int 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\n    Node *cur = hashMap->buckets[index];\n    while (cur) {\n        if (cur->pair->key == key) {\n            strcpy(cur->pair->val, val); // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n            return;\n        }\n        cur = cur->next;\n    }\n    // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n    Pair *newPair = (Pair *)malloc(sizeof(Pair));\n    newPair->key = key;\n    strcpy(newPair->val, val);\n    Node *newNode = (Node *)malloc(sizeof(Node));\n    newNode->pair = newPair;\n    newNode->next = hashMap->buckets[index];\n    hashMap->buckets[index] = newNode;\n    hashMap->size++;\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapChaining *hashMap) {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    int oldCapacity = hashMap->capacity;\n    Node **oldBuckets = hashMap->buckets;\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    hashMap->capacity *= hashMap->extendRatio;\n    hashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\n    for (int i = 0; i < hashMap->capacity; i++) {\n        hashMap->buckets[i] = NULL;\n    }\n    hashMap->size = 0;\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for (int i = 0; i < oldCapacity; i++) {\n        Node *cur = oldBuckets[i];\n        while (cur) {\n            put(hashMap, cur->pair->key, cur->pair->val);\n            Node *temp = cur;\n            cur = cur->next;\n            // \u91ca\u653e\u5185\u5b58\n            free(temp->pair);\n            free(temp);\n        }\n    }\n\n    free(oldBuckets);\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapChaining *hashMap, int key) {\n    int index = hashFunc(hashMap, key);\n    Node *cur = hashMap->buckets[index];\n    Node *pre = NULL;\n    while (cur) {\n        if (cur->pair->key == key) {\n            // \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n            if (pre) {\n                pre->next = cur->next;\n            } else {\n                hashMap->buckets[index] = cur->next;\n            }\n            // \u91ca\u653e\u5185\u5b58\n            free(cur->pair);\n            free(cur);\n            hashMap->size--;\n            return;\n        }\n        pre = cur;\n        cur = cur->next;\n    }\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapChaining *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Node *cur = hashMap->buckets[i];\n        printf(\"[\");\n        while (cur) {\n            printf(\"%d -> %s, \", cur->pair->key, cur->pair->val);\n            cur = cur->next;\n        }\n        printf(\"]\\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\u548c\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\u8fdb\u884c\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 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\uff08\u7ebf\u6027\u63a2\u6d4b\uff09\u54c8\u5e0c\u8868\u7684\u952e\u503c\u5bf9\u5206\u5e03

    \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 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\uff0cNone \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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\n        self.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\n        self.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        self.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\n        self.buckets: list[Pair | None] = [None] * self.capacity  # \u6876\u6570\u7ec4\n        self.TOMBSTONE = Pair(-1, \"-1\")  # \u5220\u9664\u6807\u8bb0\n\n    def hash_func(self, key: int) -> int:\n        \"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\n        return key % self.capacity\n\n    def load_factor(self) -> float:\n        \"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\n        return self.size / self.capacity\n\n    def find_bucket(self, key: int) -> int:\n        \"\"\"\u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\"\"\"\n        index = self.hash_func(key)\n        first_tombstone = -1\n        # \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while self.buckets[index] is not None:\n            # \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if 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\u5904\n                if first_tombstone != -1:\n                    self.buckets[first_tombstone] = self.buckets[index]\n                    self.buckets[index] = self.TOMBSTONE\n                    return first_tombstone  # \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                return index  # \u8fd4\u56de\u6876\u7d22\u5f15\n            # \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if first_tombstone == -1 and self.buckets[index] is self.TOMBSTONE:\n                first_tombstone = index\n            # \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % self.capacity\n        # \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return index if first_tombstone == -1 else first_tombstone\n\n    def get(self, key: int) -> str:\n        \"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n        # \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        index = self.find_bucket(key)\n        # \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if self.buckets[index] not in [None, self.TOMBSTONE]:\n            return self.buckets[index].val\n        # \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de None\n        return None\n\n    def 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\n        if self.load_factor() > self.load_thres:\n            self.extend()\n        # \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        index = self.find_bucket(key)\n        # \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if self.buckets[index] not in [None, self.TOMBSTONE]:\n            self.buckets[index].val = val\n            return\n        # \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        self.buckets[index] = Pair(key, val)\n        self.size += 1\n\n    def remove(self, key: int):\n        \"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n        # \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        index = self.find_bucket(key)\n        # \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if self.buckets[index] not in [None, self.TOMBSTONE]:\n            self.buckets[index] = self.TOMBSTONE\n            self.size -= 1\n\n    def extend(self):\n        \"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n        # \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        buckets_tmp = self.buckets\n        # \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio\n        self.buckets = [None] * self.capacity\n        self.size = 0\n        # \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for pair in buckets_tmp:\n            if pair not in [None, self.TOMBSTONE]:\n                self.put(pair.key, pair.val)\n\n    def print(self):\n        \"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\n        for pair in self.buckets:\n            if pair is None:\n                print(\"None\")\n            elif pair is self.TOMBSTONE:\n                print(\"TOMBSTONE\")\n            else:\n                print(pair.key, \"->\", pair.val)\n
    hash_map_open_addressing.cpp
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n  private:\n    int size;                             // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity = 4;                     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    const double loadThres = 2.0 / 3.0;     // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    const int extendRatio = 2;            // \u6269\u5bb9\u500d\u6570\n    vector<Pair *> buckets;               // \u6876\u6570\u7ec4\n    Pair *TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    HashMapOpenAddressing() : size(0), buckets(capacity, nullptr) {\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~HashMapOpenAddressing() {\n        for (Pair *pair : buckets) {\n            if (pair != nullptr && pair != TOMBSTONE) {\n                delete pair;\n            }\n        }\n        delete TOMBSTONE;\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double loadFactor() {\n        return (double)size / capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    int findBucket(int key) {\n        int index = hashFunc(key);\n        int firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (buckets[index] != nullptr) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone != -1) {\n                    buckets[firstTombstone] = buckets[index];\n                    buckets[index] = TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    string get(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\n            return buckets[index]->val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n        return \"\";\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\n            buckets[index]->val = val;\n            return;\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\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\n            delete buckets[index];\n            buckets[index] = TOMBSTONE;\n            size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        vector<Pair *> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = vector<Pair *>(capacity, nullptr);\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (Pair *pair : bucketsTmp) {\n            if (pair != nullptr && pair != TOMBSTONE) {\n                put(pair->key, pair->val);\n                delete pair;\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (Pair *pair : buckets) {\n            if (pair == nullptr) {\n                cout << \"nullptr\" << endl;\n            } else if (pair == TOMBSTONE) {\n                cout << \"TOMBSTONE\" << endl;\n            } else {\n                cout << pair->key << \" -> \" << pair->val << endl;\n            }\n        }\n    }\n};\n
    hash_map_open_addressing.java
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n    private int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    private int capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    private final double loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    private final int extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n    private Pair[] buckets; // \u6876\u6570\u7ec4\n    private final Pair TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapOpenAddressing() {\n        size = 0;\n        buckets = new Pair[capacity];\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    private double loadFactor() {\n        return (double) size / capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    private int findBucket(int key) {\n        int index = hashFunc(key);\n        int firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (buckets[index] != null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone != -1) {\n                    buckets[firstTombstone] = buckets[index];\n                    buckets[index] = TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public String get(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            return buckets[index].val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void put(int key, String val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index].val = val;\n            return;\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\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void remove(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index] = TOMBSTONE;\n            size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    private void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        Pair[] bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new Pair[capacity];\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (Pair pair : bucketsTmp) {\n            if (pair != null && pair != TOMBSTONE) {\n                put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void print() {\n        for (Pair pair : buckets) {\n            if (pair == null) {\n                System.out.println(\"null\");\n            } else if (pair == TOMBSTONE) {\n                System.out.println(\"TOMBSTONE\");\n            } else {\n                System.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 {\n    int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n    Pair[] buckets; // \u6876\u6570\u7ec4\n    Pair TOMBSTONE = new(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapOpenAddressing() {\n        size = 0;\n        buckets = new Pair[capacity];\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int HashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double LoadFactor() {\n        return (double)size / capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    int FindBucket(int key) {\n        int index = HashFunc(key);\n        int firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (buckets[index] != null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone != -1) {\n                    buckets[firstTombstone] = buckets[index];\n                    buckets[index] = TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public string? Get(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = FindBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            return buckets[index].val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void Put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (LoadFactor() > loadThres) {\n            Extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = FindBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index].val = val;\n            return;\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\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void Remove(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = FindBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index] = TOMBSTONE;\n            size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void Extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        Pair[] bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new Pair[capacity];\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        foreach (Pair pair in bucketsTmp) {\n            if (pair != null && pair != TOMBSTONE) {\n                Put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void Print() {\n        foreach (Pair pair in buckets) {\n            if (pair == null) {\n                Console.WriteLine(\"null\");\n            } else if (pair == TOMBSTONE) {\n                Console.WriteLine(\"TOMBSTONE\");\n            } else {\n                Console.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 {\n    size        int     // \u952e\u503c\u5bf9\u6570\u91cf\n    capacity    int     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    loadThres   float64 // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    extendRatio int     // \u6269\u5bb9\u500d\u6570\n    buckets     []pair  // \u6876\u6570\u7ec4\n    removed     pair    // \u5220\u9664\u6807\u8bb0\n}\n\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapOpenAddressing() *hashMapOpenAddressing {\n    buckets := make([]pair, 4)\n    return &hashMapOpenAddressing{\n        size:        0,\n        capacity:    4,\n        loadThres:   2.0 / 3.0,\n        extendRatio: 2,\n        buckets:     buckets,\n        removed: pair{\n            key: -1,\n            val: \"-1\",\n        },\n    }\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapOpenAddressing) hashFunc(key int) int {\n    return key % m.capacity\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapOpenAddressing) loadFactor() float64 {\n    return float64(m.size) / float64(m.capacity)\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) get(key int) string {\n    idx := m.hashFunc(key)\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\n    for i := 0; i < m.capacity; i++ {\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        j := (idx + i) % m.capacity\n        // \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u8fd4\u56de null\n        if m.buckets[j] == (pair{}) {\n            return \"\"\n        }\n        // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if m.buckets[j].key == key && m.buckets[j] != m.removed {\n            return m.buckets[j].val\n        }\n    }\n    // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n    return \"\"\n}\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\n    if m.loadFactor() > m.loadThres {\n        m.extend()\n    }\n    idx := m.hashFunc(key)\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\n    for i := 0; i < m.capacity; i++ {\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        j := (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\n        if m.buckets[j] == (pair{}) || m.buckets[j] == m.removed {\n            m.buckets[j] = pair{\n                key: key,\n                val: val,\n            }\n            m.size += 1\n            return\n        }\n        // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val\n        if m.buckets[j].key == key {\n            m.buckets[j].val = val\n            return\n        }\n    }\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) remove(key int) {\n    idx := 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\n    for i := 0; i < m.capacity; i++ {\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        j := (idx + i) % m.capacity\n        // \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n        if m.buckets[j] == (pair{}) {\n            return\n        }\n        // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u6807\u8bb0\u5220\u9664\u5e76\u8fd4\u56de\n        if m.buckets[j].key == key {\n            m.buckets[j] = m.removed\n            m.size -= 1\n        }\n    }\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    tmpBuckets := make([]pair, len(m.buckets))\n    copy(tmpBuckets, m.buckets)\n\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    m.capacity *= m.extendRatio\n    m.buckets = make([]pair, m.capacity)\n    m.size = 0\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for _, p := range tmpBuckets {\n        if p != (pair{}) && p != m.removed {\n            m.put(p.key, p.val)\n        }\n    }\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) print() {\n    for _, p := range m.buckets {\n        if p != (pair{}) {\n            fmt.Println(strconv.Itoa(p.key) + \" -> \" + p.val)\n        } else {\n            fmt.Println(\"nil\")\n        }\n    }\n}\n
    hash_map_open_addressing.swift
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n    var size: Int // \u952e\u503c\u5bf9\u6570\u91cf\n    var capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    var loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    var extendRatio: Int // \u6269\u5bb9\u500d\u6570\n    var buckets: [Pair?] // \u6876\u6570\u7ec4\n    var TOMBSTONE: Pair // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init() {\n        size = 0\n        capacity = 4\n        loadThres = 2.0 / 3.0\n        extendRatio = 2\n        buckets = Array(repeating: nil, count: capacity)\n        TOMBSTONE = Pair(key: -1, val: \"-1\")\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    func hashFunc(key: Int) -> Int {\n        key % capacity\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    func loadFactor() -> Double {\n        Double(size / capacity)\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    func findBucket(key: Int) -> Int {\n        var index = hashFunc(key: key)\n        var firstTombstone = -1\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while buckets[index] != nil {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if 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\u5904\n                if firstTombstone != -1 {\n                    buckets[firstTombstone] = buckets[index]\n                    buckets[index] = TOMBSTONE\n                    return firstTombstone // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if firstTombstone == -1 && buckets[index] == TOMBSTONE {\n                firstTombstone = index\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    func get(key: Int) -> String? {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = findBucket(key: key)\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if buckets[index] != nil, buckets[index] != TOMBSTONE {\n            return buckets[index]!.val\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return nil\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    func put(key: Int, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if loadFactor() > loadThres {\n            extend()\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = findBucket(key: key)\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if buckets[index] != nil, buckets[index] != TOMBSTONE {\n            buckets[index]!.val = val\n            return\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        buckets[index] = Pair(key: key, val: val)\n        size += 1\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    func remove(key: Int) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = findBucket(key: key)\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if buckets[index] != nil, buckets[index] != TOMBSTONE {\n            buckets[index] = TOMBSTONE\n            size -= 1\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    func extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let bucketsTmp = buckets\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio\n        buckets = Array(repeating: nil, count: capacity)\n        size = 0\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for pair in bucketsTmp {\n            if let pair, pair != TOMBSTONE {\n                put(key: pair.key, val: pair.val)\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    func print() {\n        for pair in buckets {\n            if pair == nil {\n                Swift.print(\"null\")\n            } else if pair == TOMBSTONE {\n                Swift.print(\"TOMBSTONE\")\n            } else {\n                Swift.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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\n        this.#capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n        this.#loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        this.#extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n        this.#buckets = Array(this.#capacity).fill(null); // \u6876\u6570\u7ec4\n        this.#TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key) {\n        return key % this.#capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    #loadFactor() {\n        return this.#size / this.#capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    #findBucket(key) {\n        let index = this.#hashFunc(key);\n        let firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (this.#buckets[index] !== null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone !== -1) {\n                    this.#buckets[firstTombstone] = this.#buckets[index];\n                    this.#buckets[index] = this.#TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (\n                firstTombstone === -1 &&\n                this.#buckets[index] === this.#TOMBSTONE\n            ) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % this.#capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone === -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.#findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (\n            this.#buckets[index] !== null &&\n            this.#buckets[index] !== this.#TOMBSTONE\n        ) {\n            return this.#buckets[index].val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key, val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.#loadFactor() > this.#loadThres) {\n            this.#extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.#findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (\n            this.#buckets[index] !== null &&\n            this.#buckets[index] !== this.#TOMBSTONE\n        ) {\n            this.#buckets[index].val = val;\n            return;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        this.#buckets[index] = new Pair(key, val);\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.#findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (\n            this.#buckets[index] !== null &&\n            this.#buckets[index] !== this.#TOMBSTONE\n        ) {\n            this.#buckets[index] = this.#TOMBSTONE;\n            this.#size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    #extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.#buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.#capacity *= this.#extendRatio;\n        this.#buckets = Array(this.#capacity).fill(null);\n        this.#size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const pair of bucketsTmp) {\n            if (pair !== null && pair !== this.#TOMBSTONE) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print() {\n        for (const pair of this.#buckets) {\n            if (pair === null) {\n                console.log('null');\n            } else if (pair === this.#TOMBSTONE) {\n                console.log('TOMBSTONE');\n            } else {\n                console.log(pair.key + ' -> ' + pair.val);\n            }\n        }\n    }\n}\n
    hash_map_open_addressing.ts
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n    private size: number; // \u952e\u503c\u5bf9\u6570\u91cf\n    private capacity: number; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    private loadThres: number; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    private extendRatio: number; // \u6269\u5bb9\u500d\u6570\n    private buckets: Array<Pair | null>; // \u6876\u6570\u7ec4\n    private TOMBSTONE: Pair; // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\n        this.capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n        this.loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        this.extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n        this.buckets = Array(this.capacity).fill(null); // \u6876\u6570\u7ec4\n        this.TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private hashFunc(key: number): number {\n        return key % this.capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    private loadFactor(): number {\n        return this.size / this.capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    private findBucket(key: number): number {\n        let index = this.hashFunc(key);\n        let firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (this.buckets[index] !== null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone !== -1) {\n                    this.buckets[firstTombstone] = this.buckets[index];\n                    this.buckets[index] = this.TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (\n                firstTombstone === -1 &&\n                this.buckets[index] === this.TOMBSTONE\n            ) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % this.capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone === -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key: number): string | null {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (\n            this.buckets[index] !== null &&\n            this.buckets[index] !== this.TOMBSTONE\n        ) {\n            return this.buckets[index]!.val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key: number, val: string): void {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.loadFactor() > this.loadThres) {\n            this.extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (\n            this.buckets[index] !== null &&\n            this.buckets[index] !== this.TOMBSTONE\n        ) {\n            this.buckets[index]!.val = val;\n            return;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        this.buckets[index] = new Pair(key, val);\n        this.size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key: number): void {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (\n            this.buckets[index] !== null &&\n            this.buckets[index] !== this.TOMBSTONE\n        ) {\n            this.buckets[index] = this.TOMBSTONE;\n            this.size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    private extend(): void {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.capacity *= this.extendRatio;\n        this.buckets = Array(this.capacity).fill(null);\n        this.size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const pair of bucketsTmp) {\n            if (pair !== null && pair !== this.TOMBSTONE) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print(): void {\n        for (const pair of this.buckets) {\n            if (pair === null) {\n                console.log('null');\n            } else if (pair === this.TOMBSTONE) {\n                console.log('TOMBSTONE');\n            } else {\n                console.log(pair.key + ' -> ' + pair.val);\n            }\n        }\n    }\n}\n
    hash_map_open_addressing.dart
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n  late int _size; // \u952e\u503c\u5bf9\u6570\u91cf\n  int _capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n  double _loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n  int _extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n  late List<Pair?> _buckets; // \u6876\u6570\u7ec4\n  Pair _TOMBSTONE = Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  HashMapOpenAddressing() {\n    _size = 0;\n    _buckets = List.generate(_capacity, (index) => null);\n  }\n\n  /* \u54c8\u5e0c\u51fd\u6570 */\n  int hashFunc(int key) {\n    return key % _capacity;\n  }\n\n  /* \u8d1f\u8f7d\u56e0\u5b50 */\n  double loadFactor() {\n    return _size / _capacity;\n  }\n\n  /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n  int findBucket(int key) {\n    int index = hashFunc(key);\n    int firstTombstone = -1;\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n    while (_buckets[index] != null) {\n      // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n      if (_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\u5904\n        if (firstTombstone != -1) {\n          _buckets[firstTombstone] = _buckets[index];\n          _buckets[index] = _TOMBSTONE;\n          return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n        }\n        return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n      }\n      // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n      if (firstTombstone == -1 && _buckets[index] == _TOMBSTONE) {\n        firstTombstone = index;\n      }\n      // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n      index = (index + 1) % _capacity;\n    }\n    // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n    return firstTombstone == -1 ? index : firstTombstone;\n  }\n\n  /* \u67e5\u8be2\u64cd\u4f5c */\n  String? get(int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    if (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n      return _buckets[index]!.val;\n    }\n    // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n    return null;\n  }\n\n  /* \u6dfb\u52a0\u64cd\u4f5c */\n  void put(int key, String val) {\n    // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n    if (loadFactor() > _loadThres) {\n      extend();\n    }\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n    if (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n      _buckets[index]!.val = val;\n      return;\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\n  /* \u5220\u9664\u64cd\u4f5c */\n  void remove(int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n    if (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n      _buckets[index] = _TOMBSTONE;\n      _size--;\n    }\n  }\n\n  /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n  void extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    List<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\n    for (Pair? pair in bucketsTmp) {\n      if (pair != null && pair != _TOMBSTONE) {\n        put(pair.key, pair.val);\n      }\n    }\n  }\n\n  /* \u6253\u5370\u54c8\u5e0c\u8868 */\n  void printHashMap() {\n    for (Pair? pair in _buckets) {\n      if (pair == null) {\n        print(\"null\");\n      } else if (pair == _TOMBSTONE) {\n        print(\"TOMBSTONE\");\n      } else {\n        print(\"${pair.key} -> ${pair.val}\");\n      }\n    }\n  }\n}\n
    hash_map_open_addressing.rs
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapOpenAddressing {\n    size: usize,                    // \u952e\u503c\u5bf9\u6570\u91cf\n    capacity: usize,                // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    load_thres: f64,                // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    extend_ratio: usize,            // \u6269\u5bb9\u500d\u6570\n    buckets: Vec<Option<Pair>>,     // \u6876\u6570\u7ec4\n    TOMBSTONE: Option<Pair>,        // \u5220\u9664\u6807\u8bb0\n}\n\n\nimpl HashMapOpenAddressing {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new() -> Self {\n        Self {\n            size: 0,\n            capacity: 4,\n            load_thres: 2.0 / 3.0,\n            extend_ratio: 2,\n            buckets: vec![None; 4],\n            TOMBSTONE: Some(Pair {key: -1, val: \"-1\".to_string()}),\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    fn hash_func(&self, key: i32) -> usize {\n        (key % self.capacity as i32) as usize\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    fn load_factor(&self) -> f64 {\n        self.size as f64 / self.capacity as f64\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    fn find_bucket(&mut self, key: i32) -> usize {\n        let mut index = self.hash_func(key);\n        let mut first_tombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while self.buckets[index].is_some() {\n            // \u82e5\u9047\u5230 key\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if 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\n                if first_tombstone != -1 {\n                    self.buckets[first_tombstone as usize] = self.buckets[index].take();\n                    self.buckets[index] = self.TOMBSTONE.clone();\n                    return first_tombstone as usize;    // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index;   // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if first_tombstone == -1 && self.buckets[index] == self.TOMBSTONE {\n                first_tombstone = index as i32;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % self.capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        if first_tombstone == -1 { index } else { first_tombstone as usize }\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    fn get(&mut self, key: i32) -> Option<&str> {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = self.find_bucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\n            return 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\n        None\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    fn put(&mut self, key: i32, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if self.load_factor() > self.load_thres {\n            self.extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = self.find_bucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\n            self.buckets[index].as_mut().unwrap().val = val;\n            return;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        self.buckets[index] = Some(Pair { key, val });\n        self.size += 1;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    fn remove(&mut self, key: i32) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = self.find_bucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\n            self.buckets[index] = self.TOMBSTONE.clone();\n            self.size -= 1;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    fn extend(&mut self) {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let buckets_tmp = self.buckets.clone();\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio;\n        self.buckets = vec![None; self.capacity];\n        self.size = 0;\n\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for pair in buckets_tmp {\n            if pair.is_none() || pair == self.TOMBSTONE {\n                continue;\n            }\n            let pair = pair.unwrap();\n\n            self.put(pair.key, pair.val);\n        }\n    }\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    fn print(&self) {\n        for pair in &self.buckets {\n            if pair.is_none() {\n                println!(\"null\");\n            } else if pair == &self.TOMBSTONE {\n                println!(\"TOMBSTONE\");\n            } else {\n                let pair = pair.as_ref().unwrap();\n                println!(\"{} -> {}\", pair.key, pair.val);\n            }\n        }\n    }\n}\n
    hash_map_open_addressing.c
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\n    int size;         // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio;  // \u6269\u5bb9\u500d\u6570\n    Pair **buckets;   // \u6876\u6570\u7ec4\n    Pair *TOMBSTONE;  // \u5220\u9664\u6807\u8bb0\n} HashMapOpenAddressing;\n\n/* \u6784\u9020\u51fd\u6570 */\nHashMapOpenAddressing *newHashMapOpenAddressing() {\n    HashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));\n    hashMap->size = 0;\n    hashMap->capacity = 4;\n    hashMap->loadThres = 2.0 / 3.0;\n    hashMap->extendRatio = 2;\n    hashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\n    hashMap->TOMBSTONE = (Pair *)malloc(sizeof(Pair));\n    hashMap->TOMBSTONE->key = -1;\n    hashMap->TOMBSTONE->val = \"-1\";\n\n    return hashMap;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Pair *pair = hashMap->buckets[i];\n        if (pair != NULL && pair != hashMap->TOMBSTONE) {\n            free(pair->val);\n            free(pair);\n        }\n    }\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapOpenAddressing *hashMap, int key) {\n    return key % hashMap->capacity;\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapOpenAddressing *hashMap) {\n    return (double)hashMap->size / (double)hashMap->capacity;\n}\n\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(HashMapOpenAddressing *hashMap, int key) {\n    int index = hashFunc(hashMap, key);\n    int firstTombstone = -1;\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n    while (hashMap->buckets[index] != NULL) {\n        // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        if (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\u5904\n            if (firstTombstone != -1) {\n                hashMap->buckets[firstTombstone] = hashMap->buckets[index];\n                hashMap->buckets[index] = hashMap->TOMBSTONE;\n                return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n            }\n            return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n        }\n        // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n        if (firstTombstone == -1 && hashMap->buckets[index] == hashMap->TOMBSTONE) {\n            firstTombstone = index;\n        }\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        index = (index + 1) % hashMap->capacity;\n    }\n    // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n    return firstTombstone == -1 ? index : firstTombstone;\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapOpenAddressing *hashMap, int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(hashMap, key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\n        return hashMap->buckets[index]->val;\n    }\n    // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n    return \"\";\n}\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\n    if (loadFactor(hashMap) > hashMap->loadThres) {\n        extend(hashMap);\n    }\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(hashMap, key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n    if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\n        free(hashMap->buckets[index]->val);\n        hashMap->buckets[index]->val = (char *)malloc(sizeof(strlen(val + 1)));\n        strcpy(hashMap->buckets[index]->val, val);\n        hashMap->buckets[index]->val[strlen(val)] = '\\0';\n        return;\n    }\n    // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n    Pair *pair = (Pair *)malloc(sizeof(Pair));\n    pair->key = key;\n    pair->val = (char *)malloc(sizeof(strlen(val + 1)));\n    strcpy(pair->val, val);\n    pair->val[strlen(val)] = '\\0';\n\n    hashMap->buckets[index] = pair;\n    hashMap->size++;\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapOpenAddressing *hashMap, int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(hashMap, key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n    if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\n        Pair *pair = hashMap->buckets[index];\n        free(pair->val);\n        free(pair);\n        hashMap->buckets[index] = hashMap->TOMBSTONE;\n        hashMap->size--;\n    }\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapOpenAddressing *hashMap) {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    Pair **bucketsTmp = hashMap->buckets;\n    int oldCapacity = hashMap->capacity;\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    hashMap->capacity *= hashMap->extendRatio;\n    hashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\n    hashMap->size = 0;\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for (int i = 0; i < oldCapacity; i++) {\n        Pair *pair = bucketsTmp[i];\n        if (pair != NULL && pair != hashMap->TOMBSTONE) {\n            put(hashMap, pair->key, pair->val);\n            free(pair->val);\n            free(pair);\n        }\n    }\n    free(bucketsTmp);\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapOpenAddressing *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Pair *pair = hashMap->buckets[i];\n        if (pair == NULL) {\n            printf(\"NULL\\n\");\n        } else if (pair == hashMap->TOMBSTONE) {\n            printf(\"TOMBSTONE\\n\");\n        } else {\n            printf(\"%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\u63a2\u6d4b\u6b21\u6570\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\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\u4f4d\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\u4f4d\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 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\u79cd\u7f16\u7a0b\u8bed\u8a00\u91c7\u53d6\u4e86\u4e0d\u540c\u7684\u54c8\u5e0c\u8868\u5b9e\u73b0\u7b56\u7565\uff0c\u4e0b\u9762\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\uff1b\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\u5b83\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\u4e2d\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\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\n# \u67e5\u8be2\u64cd\u4f5c\n# \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname: str = hmap[15937]\n\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n\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\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.put(12836, \"\u5c0f\u54c8\");   \nmap.put(15937, \"\u5c0f\u5570\");   \nmap.put(16750, \"\u5c0f\u7b97\");   \nmap.put(13276, \"\u5c0f\u6cd5\");\nmap.put(10583, \"\u5c0f\u9e2d\");\n\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map.get(15937);\n\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname := hmap[15937]\n\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map[15937]!\n\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map.get(15937);\n\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\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\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map[15937];\n\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\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nlet mut map: HashMap<i32, String> = HashMap::new();\n\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\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\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():\n    print(key, \"->\", value)\n# \u5355\u72ec\u904d\u5386\u952e key\nfor key in hmap.keys():\n    print(key)\n# \u5355\u72ec\u904d\u5386\u503c value\nfor value in hmap.values():\n    print(value)\n
    hash_map.cpp
    /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor (auto kv: map) {\n    cout << 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++) {\n    cout << 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()) {\n    System.out.println(kv.getKey() + \" -> \" + kv.getValue());\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor (int key: map.keySet()) {\n    System.out.println(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor (String val: map.values()) {\n    System.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) {\n    Console.WriteLine(kv.Key + \" -> \" + kv.Value);\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nforeach (int key in map.Keys) {\n    Console.WriteLine(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nforeach (string val in map.Values) {\n    Console.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 {\n    fmt.Println(key, \"->\", value)\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor key := range hmap {\n    fmt.Println(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor _, value := range hmap {\n    fmt.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 {\n    print(\"\\(key) -> \\(value)\")\n}\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys {\n    print(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values {\n    print(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()) {\n    console.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\n    console.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\n    console.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()) {\n    console.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\n    console.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\n    console.info(v);\n}\n
    hash_map.dart
    /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nmap.forEach((key, value) {\n  print('$key -> $value');\n});\n\n// \u5355\u72ec\u904d\u5386\u952e Key\nmap.keys.forEach((key) {\n  print(key);\n});\n\n// \u5355\u72ec\u904d\u5386\u503c Value\nmap.values.forEach((value) {\n  print(value);\n});\n
    hash_map.rs
    /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nfor (key, value) in &map {\n    println!(\"{key} -> {value}\");\n}\n\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys() {\n    println!(\"{key}\"); \n}\n\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values() {\n    println!(\"{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\"\"\"\n\n    def __init__(self, key: int, val: str):\n        self.key = key\n        self.val = val\n\nclass ArrayHashMap:\n    \"\"\"\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        # \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        self.buckets: list[Pair | None] = [None] * 100\n\n    def hash_func(self, key: int) -> int:\n        \"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\n        index = key % 100\n        return index\n\n    def get(self, key: int) -> str:\n        \"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n        index: int = self.hash_func(key)\n        pair: Pair = self.buckets[index]\n        if pair is None:\n            return None\n        return pair.val\n\n    def put(self, key: int, val: str):\n        \"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\n        pair = Pair(key, val)\n        index: int = self.hash_func(key)\n        self.buckets[index] = pair\n\n    def remove(self, key: int):\n        \"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n        index: int = self.hash_func(key)\n        # \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\n        self.buckets[index] = None\n\n    def entry_set(self) -> list[Pair]:\n        \"\"\"\u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\"\"\"\n        result: list[Pair] = []\n        for pair in self.buckets:\n            if pair is not None:\n                result.append(pair)\n        return result\n\n    def key_set(self) -> list[int]:\n        \"\"\"\u83b7\u53d6\u6240\u6709\u952e\"\"\"\n        result = []\n        for pair in self.buckets:\n            if pair is not None:\n                result.append(pair.key)\n        return result\n\n    def value_set(self) -> list[str]:\n        \"\"\"\u83b7\u53d6\u6240\u6709\u503c\"\"\"\n        result = []\n        for pair in self.buckets:\n            if pair is not None:\n                result.append(pair.val)\n        return result\n\n    def print(self):\n        \"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\n        for pair in self.buckets:\n            if pair is not None:\n                print(pair.key, \"->\", pair.val)\n
    array_hash_map.cpp
    /* \u952e\u503c\u5bf9 */\nstruct Pair {\n  public:\n    int key;\n    string val;\n    Pair(int key, string val) {\n        this->key = key;\n        this->val = val;\n    }\n};\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n  private:\n    vector<Pair *> buckets;\n\n  public:\n    ArrayHashMap() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        buckets = vector<Pair *>(100);\n    }\n\n    ~ArrayHashMap() {\n        // \u91ca\u653e\u5185\u5b58\n        for (const auto &bucket : buckets) {\n            delete bucket;\n        }\n        buckets.clear();\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        int index = key % 100;\n        return index;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    string get(int key) {\n        int index = hashFunc(key);\n        Pair *pair = buckets[index];\n        if (pair == nullptr)\n            return \"\";\n        return pair->val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, string val) {\n        Pair *pair = new Pair(key, val);\n        int index = hashFunc(key);\n        buckets[index] = pair;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        int index = hashFunc(key);\n        // \u91ca\u653e\u5185\u5b58\u5e76\u7f6e\u4e3a nullptr\n        delete buckets[index];\n        buckets[index] = nullptr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    vector<Pair *> pairSet() {\n        vector<Pair *> pairSet;\n        for (Pair *pair : buckets) {\n            if (pair != nullptr) {\n                pairSet.push_back(pair);\n            }\n        }\n        return pairSet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    vector<int> keySet() {\n        vector<int> keySet;\n        for (Pair *pair : buckets) {\n            if (pair != nullptr) {\n                keySet.push_back(pair->key);\n            }\n        }\n        return keySet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    vector<string> valueSet() {\n        vector<string> valueSet;\n        for (Pair *pair : buckets) {\n            if (pair != nullptr) {\n                valueSet.push_back(pair->val);\n            }\n        }\n        return valueSet;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (Pair *kv : pairSet()) {\n            cout << kv->key << \" -> \" << kv->val << endl;\n        }\n    }\n};\n
    array_hash_map.java
    /* \u952e\u503c\u5bf9 */\nclass Pair {\n    public int key;\n    public String val;\n\n    public Pair(int key, String val) {\n        this.key = key;\n        this.val = val;\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    private List<Pair> buckets;\n\n    public ArrayHashMap() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        buckets = new ArrayList<>();\n        for (int i = 0; i < 100; i++) {\n            buckets.add(null);\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private int hashFunc(int key) {\n        int index = key % 100;\n        return index;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public String get(int key) {\n        int index = hashFunc(key);\n        Pair pair = buckets.get(index);\n        if (pair == null)\n            return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void put(int key, String val) {\n        Pair pair = new Pair(key, val);\n        int index = hashFunc(key);\n        buckets.set(index, pair);\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void remove(int key) {\n        int index = hashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        buckets.set(index, null);\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    public List<Pair> pairSet() {\n        List<Pair> pairSet = new ArrayList<>();\n        for (Pair pair : buckets) {\n            if (pair != null)\n                pairSet.add(pair);\n        }\n        return pairSet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    public List<Integer> keySet() {\n        List<Integer> keySet = new ArrayList<>();\n        for (Pair pair : buckets) {\n            if (pair != null)\n                keySet.add(pair.key);\n        }\n        return keySet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    public List<String> valueSet() {\n        List<String> valueSet = new ArrayList<>();\n        for (Pair pair : buckets) {\n            if (pair != null)\n                valueSet.add(pair.val);\n        }\n        return valueSet;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void print() {\n        for (Pair kv : pairSet()) {\n            System.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) {\n    public int key = key;\n    public string val = val;\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    List<Pair?> buckets;\n    public ArrayHashMap() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        buckets = [];\n        for (int i = 0; i < 100; i++) {\n            buckets.Add(null);\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int HashFunc(int key) {\n        int index = key % 100;\n        return index;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public string? Get(int key) {\n        int index = HashFunc(key);\n        Pair? pair = buckets[index];\n        if (pair == null) return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void Put(int key, string val) {\n        Pair pair = new(key, val);\n        int index = HashFunc(key);\n        buckets[index] = pair;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void Remove(int key) {\n        int index = HashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        buckets[index] = null;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    public List<Pair> PairSet() {\n        List<Pair> pairSet = [];\n        foreach (Pair? pair in buckets) {\n            if (pair != null)\n                pairSet.Add(pair);\n        }\n        return pairSet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    public List<int> KeySet() {\n        List<int> keySet = [];\n        foreach (Pair? pair in buckets) {\n            if (pair != null)\n                keySet.Add(pair.key);\n        }\n        return keySet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    public List<string> ValueSet() {\n        List<string> valueSet = [];\n        foreach (Pair? pair in buckets) {\n            if (pair != null)\n                valueSet.Add(pair.val);\n        }\n        return valueSet;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void Print() {\n        foreach (Pair kv in PairSet()) {\n            Console.WriteLine(kv.key + \" -> \" + kv.val);\n        }\n    }\n}\n
    array_hash_map.go
    /* \u952e\u503c\u5bf9 */\ntype pair struct {\n    key int\n    val string\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntype arrayHashMap struct {\n    buckets []*pair\n}\n\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nfunc newArrayHashMap() *arrayHashMap {\n    // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n    buckets := make([]*pair, 100)\n    return &arrayHashMap{buckets: buckets}\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (a *arrayHashMap) hashFunc(key int) int {\n    index := key % 100\n    return index\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (a *arrayHashMap) get(key int) string {\n    index := a.hashFunc(key)\n    pair := a.buckets[index]\n    if pair == nil {\n        return \"Not Found\"\n    }\n    return pair.val\n}\n\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (a *arrayHashMap) put(key int, val string) {\n    pair := &pair{key: key, val: val}\n    index := a.hashFunc(key)\n    a.buckets[index] = pair\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (a *arrayHashMap) remove(key int) {\n    index := a.hashFunc(key)\n    // \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\n    a.buckets[index] = nil\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e\u5bf9 */\nfunc (a *arrayHashMap) pairSet() []*pair {\n    var pairs []*pair\n    for _, pair := range a.buckets {\n        if pair != nil {\n            pairs = append(pairs, pair)\n        }\n    }\n    return pairs\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e */\nfunc (a *arrayHashMap) keySet() []int {\n    var keys []int\n    for _, pair := range a.buckets {\n        if pair != nil {\n            keys = append(keys, pair.key)\n        }\n    }\n    return keys\n}\n\n/* \u83b7\u53d6\u6240\u6709\u503c */\nfunc (a *arrayHashMap) valueSet() []string {\n    var values []string\n    for _, pair := range a.buckets {\n        if pair != nil {\n            values = append(values, pair.val)\n        }\n    }\n    return values\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (a *arrayHashMap) print() {\n    for _, pair := range a.buckets {\n        if pair != nil {\n            fmt.Println(pair.key, \"->\", pair.val)\n        }\n    }\n}\n
    array_hash_map.swift
    /* \u952e\u503c\u5bf9 */\nclass Pair: Equatable {\n    public var key: Int\n    public var val: String\n\n    public init(key: Int, val: String) {\n        self.key = key\n        self.val = val\n    }\n\n    public static func == (lhs: Pair, rhs: Pair) -> Bool {\n        lhs.key == rhs.key && lhs.val == rhs.val\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    private var buckets: [Pair?] = []\n\n    init() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        for _ in 0 ..< 100 {\n            buckets.append(nil)\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private func hashFunc(key: Int) -> Int {\n        let index = key % 100\n        return index\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    func get(key: Int) -> String? {\n        let index = hashFunc(key: key)\n        let pair = buckets[index]\n        return pair?.val\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    func put(key: Int, val: String) {\n        let pair = Pair(key: key, val: val)\n        let index = hashFunc(key: key)\n        buckets[index] = pair\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    func remove(key: Int) {\n        let index = hashFunc(key: key)\n        // \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\n        buckets[index] = nil\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    func pairSet() -> [Pair] {\n        var pairSet: [Pair] = []\n        for pair in buckets {\n            if let pair = pair {\n                pairSet.append(pair)\n            }\n        }\n        return pairSet\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    func keySet() -> [Int] {\n        var keySet: [Int] = []\n        for pair in buckets {\n            if let pair = pair {\n                keySet.append(pair.key)\n            }\n        }\n        return keySet\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    func valueSet() -> [String] {\n        var valueSet: [String] = []\n        for pair in buckets {\n            if let pair = pair {\n                valueSet.append(pair.val)\n            }\n        }\n        return valueSet\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    func print() {\n        for pair in pairSet() {\n            Swift.print(\"\\(pair.key) -> \\(pair.val)\")\n        }\n    }\n}\n
    array_hash_map.js
    /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\n    constructor(key, val) {\n        this.key = key;\n        this.val = val;\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    #buckets;\n    constructor() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        this.#buckets = new Array(100).fill(null);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key) {\n        return key % 100;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key) {\n        let index = this.#hashFunc(key);\n        let pair = this.#buckets[index];\n        if (pair === null) return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    set(key, val) {\n        let index = this.#hashFunc(key);\n        this.#buckets[index] = new Pair(key, val);\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    delete(key) {\n        let index = this.#hashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        this.#buckets[index] = null;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    entries() {\n        let arr = [];\n        for (let i = 0; i < this.#buckets.length; i++) {\n            if (this.#buckets[i]) {\n                arr.push(this.#buckets[i]);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    keys() {\n        let arr = [];\n        for (let i = 0; i < this.#buckets.length; i++) {\n            if (this.#buckets[i]) {\n                arr.push(this.#buckets[i].key);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    values() {\n        let arr = [];\n        for (let i = 0; i < this.#buckets.length; i++) {\n            if (this.#buckets[i]) {\n                arr.push(this.#buckets[i].val);\n            }\n        }\n        return arr;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print() {\n        let pairSet = this.entries();\n        for (const pair of pairSet) {\n            console.info(`${pair.key} -> ${pair.val}`);\n        }\n    }\n}\n
    array_hash_map.ts
    /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\n    public key: number;\n    public val: string;\n\n    constructor(key: number, val: string) {\n        this.key = key;\n        this.val = val;\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    private readonly buckets: (Pair | null)[];\n\n    constructor() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        this.buckets = new Array(100).fill(null);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private hashFunc(key: number): number {\n        return key % 100;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public get(key: number): string | null {\n        let index = this.hashFunc(key);\n        let pair = this.buckets[index];\n        if (pair === null) return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public set(key: number, val: string) {\n        let index = this.hashFunc(key);\n        this.buckets[index] = new Pair(key, val);\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public delete(key: number) {\n        let index = this.hashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        this.buckets[index] = null;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    public entries(): (Pair | null)[] {\n        let arr: (Pair | null)[] = [];\n        for (let i = 0; i < this.buckets.length; i++) {\n            if (this.buckets[i]) {\n                arr.push(this.buckets[i]);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    public keys(): (number | undefined)[] {\n        let arr: (number | undefined)[] = [];\n        for (let i = 0; i < this.buckets.length; i++) {\n            if (this.buckets[i]) {\n                arr.push(this.buckets[i].key);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    public values(): (string | undefined)[] {\n        let arr: (string | undefined)[] = [];\n        for (let i = 0; i < this.buckets.length; i++) {\n            if (this.buckets[i]) {\n                arr.push(this.buckets[i].val);\n            }\n        }\n        return arr;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public print() {\n        let pairSet = this.entries();\n        for (const pair of pairSet) {\n            console.info(`${pair.key} -> ${pair.val}`);\n        }\n    }\n}\n
    array_hash_map.dart
    /* \u952e\u503c\u5bf9 */\nclass Pair {\n  int key;\n  String val;\n  Pair(this.key, this.val);\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n  late List<Pair?> _buckets;\n\n  ArrayHashMap() {\n    // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n    _buckets = List.filled(100, null);\n  }\n\n  /* \u54c8\u5e0c\u51fd\u6570 */\n  int _hashFunc(int key) {\n    final int index = key % 100;\n    return index;\n  }\n\n  /* \u67e5\u8be2\u64cd\u4f5c */\n  String? get(int key) {\n    final int index = _hashFunc(key);\n    final Pair? pair = _buckets[index];\n    if (pair == null) {\n      return null;\n    }\n    return pair.val;\n  }\n\n  /* \u6dfb\u52a0\u64cd\u4f5c */\n  void put(int key, String val) {\n    final Pair pair = Pair(key, val);\n    final int index = _hashFunc(key);\n    _buckets[index] = pair;\n  }\n\n  /* \u5220\u9664\u64cd\u4f5c */\n  void remove(int key) {\n    final int index = _hashFunc(key);\n    _buckets[index] = null;\n  }\n\n  /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n  List<Pair> pairSet() {\n    List<Pair> pairSet = [];\n    for (final Pair? pair in _buckets) {\n      if (pair != null) {\n        pairSet.add(pair);\n      }\n    }\n    return pairSet;\n  }\n\n  /* \u83b7\u53d6\u6240\u6709\u952e */\n  List<int> keySet() {\n    List<int> keySet = [];\n    for (final Pair? pair in _buckets) {\n      if (pair != null) {\n        keySet.add(pair.key);\n      }\n    }\n    return keySet;\n  }\n\n  /* \u83b7\u53d6\u6240\u6709\u503c */\n  List<String> values() {\n    List<String> valueSet = [];\n    for (final Pair? pair in _buckets) {\n      if (pair != null) {\n        valueSet.add(pair.val);\n      }\n    }\n    return valueSet;\n  }\n\n  /* \u6253\u5370\u54c8\u5e0c\u8868 */\n  void printHashMap() {\n    for (final Pair kv in pairSet()) {\n      print(\"${kv.key} -> ${kv.val}\");\n    }\n  }\n}\n
    array_hash_map.rs
    /* \u952e\u503c\u5bf9 */\n#[derive(Debug, Clone, PartialEq)]\npub struct Pair {\n    pub key: i32,\n    pub val: String,\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\npub struct ArrayHashMap {\n    buckets: Vec<Option<Pair>>\n}\n\nimpl ArrayHashMap {\n    pub fn new() -> ArrayHashMap {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        Self { buckets: vec![None; 100] }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    fn hash_func(&self, key: i32) -> usize {\n        key as usize % 100\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    pub fn get(&self, key: i32) -> Option<&String> {\n        let index = self.hash_func(key);\n        self.buckets[index].as_ref().map(|pair| &pair.val)\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    pub fn put(&mut self, key: i32, val: &str) {\n        let index = self.hash_func(key);\n        self.buckets[index] = Some(Pair {\n            key,\n            val: val.to_string(),\n        });\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    pub fn remove(&mut self, key: i32) {\n        let index = self.hash_func(key);\n        // \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\n        self.buckets[index] = None;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    pub fn entry_set(&self) -> Vec<&Pair> {\n        self.buckets.iter().filter_map(|pair| pair.as_ref()).collect()\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    pub fn key_set(&self) -> Vec<&i32> {\n        self.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.key)).collect()\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    pub fn value_set(&self) -> Vec<&String> {\n        self.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.val)).collect()\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    pub fn print(&self) {\n        for pair in self.entry_set() {\n            println!(\"{} -> {}\", pair.key, pair.val);\n        }\n    }\n}\n
    array_hash_map.c
    /* \u952e\u503c\u5bf9 int->string */\ntypedef struct {\n    int key;\n    char *val;\n} Pair;\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntypedef struct {\n    Pair *buckets[HASHTABLE_CAPACITY];\n} ArrayHashMap;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayHashMap *newArrayHashMap() {\n    ArrayHashMap *hmap = malloc(sizeof(ArrayHashMap));\n    return hmap;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayHashMap(ArrayHashMap *hmap) {\n    for (int i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            free(hmap->buckets[i]->val);\n            free(hmap->buckets[i]);\n        }\n    }\n    free(hmap);\n}\n\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(ArrayHashMap *hmap, const int key, const char *val) {\n    Pair *Pair = malloc(sizeof(Pair));\n    Pair->key = key;\n    Pair->val = malloc(strlen(val) + 1);\n    strcpy(Pair->val, val);\n\n    int index = hashFunc(key);\n    hmap->buckets[index] = Pair;\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(ArrayHashMap *hmap, const int key) {\n    int index = hashFunc(key);\n    free(hmap->buckets[index]->val);\n    free(hmap->buckets[index]);\n    hmap->buckets[index] = NULL;\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nvoid pairSet(ArrayHashMap *hmap, MapSet *set) {\n    Pair *entries;\n    int i = 0, index = 0;\n    int total = 0;\n    /* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            total++;\n        }\n    }\n    entries = malloc(sizeof(Pair) * total);\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            entries[index].key = hmap->buckets[i]->key;\n            entries[index].val = malloc(strlen(hmap->buckets[i]->val) + 1);\n            strcpy(entries[index].val, hmap->buckets[i]->val);\n            index++;\n        }\n    }\n    set->set = entries;\n    set->len = total;\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e */\nvoid keySet(ArrayHashMap *hmap, MapSet *set) {\n    int *keys;\n    int i = 0, index = 0;\n    int total = 0;\n    /* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            total++;\n        }\n    }\n    keys = malloc(total * sizeof(int));\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            keys[index] = hmap->buckets[i]->key;\n            index++;\n        }\n    }\n    set->set = keys;\n    set->len = total;\n}\n\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvoid valueSet(ArrayHashMap *hmap, MapSet *set) {\n    char **vals;\n    int i = 0, index = 0;\n    int total = 0;\n    /* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            total++;\n        }\n    }\n    vals = malloc(total * sizeof(char *));\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            vals[index] = hmap->buckets[i]->val;\n            index++;\n        }\n    }\n    set->set = vals;\n    set->len = total;\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(ArrayHashMap *hmap) {\n    int i;\n    MapSet set;\n    pairSet(hmap, &set);\n    Pair *entries = (Pair *)set.set;\n    for (i = 0; i < set.len; i++) {\n        printf(\"%d -> %s\\n\", entries[i].key, entries[i].val);\n    }\n    free(set.set);\n}\n
    array_hash_map.zig
    // \u952e\u503c\u5bf9\nconst Pair = struct {\n    key: usize = undefined,\n    val: []const u8 = undefined,\n\n   pub fn init(key: usize, val: []const u8) Pair {\n        return Pair {\n            .key = key,\n            .val = val,\n        };\n    }\n};\n\n// \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\nfn ArrayHashMap(comptime T: type) type {\n    return struct {\n        bucket: ?std.ArrayList(?T) = null,\n        mem_allocator: std.mem.Allocator = undefined,\n\n        const Self = @This();\n\n        // \u6784\u9020\u51fd\u6570\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            self.mem_allocator = allocator;\n            // \u521d\u59cb\u5316\u4e00\u4e2a\u957f\u5ea6\u4e3a 100 \u7684\u6876\uff08\u6570\u7ec4\uff09\n            self.bucket = std.ArrayList(?T).init(self.mem_allocator);\n            var i: i32 = 0;\n            while (i < 100) : (i += 1) {\n                try self.bucket.?.append(null);\n            }\n        }\n\n        // \u6790\u6784\u51fd\u6570\n        pub fn deinit(self: *Self) void {\n            if (self.bucket != null) self.bucket.?.deinit();\n        }\n\n        // \u54c8\u5e0c\u51fd\u6570\n        fn hashFunc(key: usize) usize {\n            var index = key % 100;\n            return index;\n        }\n\n        // \u67e5\u8be2\u64cd\u4f5c\n        pub fn get(self: *Self, key: usize) []const u8 {\n            var index = hashFunc(key);\n            var pair = self.bucket.?.items[index];\n            return pair.?.val;\n        }\n\n        // \u6dfb\u52a0\u64cd\u4f5c\n        pub fn put(self: *Self, key: usize, val: []const u8) !void {\n            var pair = Pair.init(key, val);\n            var index = hashFunc(key);\n            self.bucket.?.items[index] = pair;\n        }\n\n        // \u5220\u9664\u64cd\u4f5c\n        pub fn remove(self: *Self, key: usize) !void {\n            var index = hashFunc(key);\n            // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n            self.bucket.?.items[index] = null;\n        }       \n\n        // \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\n        pub fn pairSet(self: *Self) !std.ArrayList(T) {\n            var entry_set = std.ArrayList(T).init(self.mem_allocator);\n            for (self.bucket.?.items) |item| {\n                if (item == null) continue;\n                try entry_set.append(item.?);\n            }\n            return entry_set;\n        }  \n\n        // \u83b7\u53d6\u6240\u6709\u952e\n        pub fn keySet(self: *Self) !std.ArrayList(usize) {\n            var key_set = std.ArrayList(usize).init(self.mem_allocator);\n            for (self.bucket.?.items) |item| {\n                if (item == null) continue;\n                try key_set.append(item.?.key);\n            }\n            return key_set;\n        }  \n\n        // \u83b7\u53d6\u6240\u6709\u503c\n        pub fn valueSet(self: *Self) !std.ArrayList([]const u8) {\n            var value_set = std.ArrayList([]const u8).init(self.mem_allocator);\n            for (self.bucket.?.items) |item| {\n                if (item == null) continue;\n                try value_set.append(item.?.val);\n            }\n            return value_set;\n        }\n\n        // \u6253\u5370\u54c8\u5e0c\u8868\n        pub fn print(self: *Self) !void {\n            var entry_set = try self.pairSet();\n            defer entry_set.deinit();\n            for (entry_set.items) |item| {\n                std.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\u589e\u52a0\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\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\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\u6a21\uff08\u53d6\u4f59\uff09\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\u5730\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\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\u7531\u4e8e\u53f6\u8282\u70b9\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u56e0\u6b64\u5b83\u4eec\u5929\u7136\u5c31\u662f\u5408\u6cd5\u7684\u5b50\u5806\uff0c\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\uff1a

    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\n    self.max_heap = nums\n    # \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for i in range(self.parent(self.size() - 1), -1, -1):\n        self.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\n    maxHeap = nums;\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (int i = parent(size() - 1); i >= 0; i--) {\n        siftDown(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\n    maxHeap = new ArrayList<>(nums);\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (int i = parent(size() - 1); i >= 0; i--) {\n        siftDown(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\n    maxHeap = new List<int>(nums);\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    var size = Parent(this.Size() - 1);\n    for (int i = size; i >= 0; i--) {\n        SiftDown(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\n    h := &maxHeap{data: nums}\n    for 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\n        h.siftDown(i)\n    }\n    return 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\n    maxHeap = nums\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for i in stride(from: parent(i: size() - 1), through: 0, by: -1) {\n        siftDown(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\n    this.#maxHeap = nums === undefined ? [] : [...nums];\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (let i = this.#parent(this.size() - 1); i >= 0; i--) {\n        this.#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\n    this.maxHeap = nums === undefined ? [] : [...nums];\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (let i = this.parent(this.size() - 1); i >= 0; i--) {\n        this.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\n  for (int i = _parent(size() - 1); i >= 0; i--) {\n    siftDown(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\n    let mut heap = MaxHeap { max_heap: nums };\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for i in (0..=Self::parent(heap.size() - 1)).rev() {\n        heap.sift_down(i);\n    }\n    heap\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\n    MaxHeap *maxHeap = (MaxHeap *)malloc(sizeof(MaxHeap));\n    maxHeap->size = size;\n    memcpy(maxHeap->data, nums, size * sizeof(int));\n    for (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\n        siftDown(maxHeap, i);\n    }\n    return 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 {\n    if (self.max_heap != null) return;\n    self.max_heap = std.ArrayList(T).init(allocator);\n    // \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\n    try self.max_heap.?.appendSlice(nums);\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    var i: usize = parent(self.size() - 1) + 1;\n    while (i > 0) : (i -= 1) {\n        try 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\u5c06\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\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\u5c0f\u9876\u5806 min heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\leq\\) \u5176\u5b50\u8282\u70b9\u7684\u503c\u3002
    • \u300c\u5927\u9876\u5806 max heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\geq\\) \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\u662f\u6700\u5927\uff08\u6700\u5c0f\uff09\u7684\u3002
    "},{"location":"chapter_heap/heap/#811","title":"8.1.1 \u00a0 \u5806\u7684\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\u7684\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\u5bf9\u4e8e\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\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\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\n# \u83b7\u53d6\u5806\u9876\u5143\u7d20\npeek: int = flag * max_heap[0] # 5\n\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\n# \u83b7\u53d6\u5806\u5927\u5c0f\nsize: int = len(max_heap)\n\n# \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = not max_heap\n\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\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.push(1);\nmaxHeap.push(3);\nmaxHeap.push(2);\nmaxHeap.push(5);\nmaxHeap.push(4);\n\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.top(); // 5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.empty();\n\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\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.offer(1);\nmaxHeap.offer(3);\nmaxHeap.offer(2);\nmaxHeap.offer(5);\nmaxHeap.offer(4);\n\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.peek(); // 5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = maxHeap.isEmpty();\n\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\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\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.Peek();//5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.Count;\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.Count == 0;\n\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\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\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\n    last := (*h)[len(*h)-1]\n    *h = (*h)[:len(*h)-1]\n    return last\n}\n\n// Len sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Len() int {\n    return len(*h)\n}\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\n    return (*h)[i].(int) > (*h)[j].(int)\n}\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\n// Top \u83b7\u53d6\u5806\u9876\u5143\u7d20\nfunc (h *intHeap) Top() any {\n    return (*h)[0]\n}\n\n/* Driver Code */\nfunc TestHeap(t *testing.T) {\n    /* \u521d\u59cb\u5316\u5806 */\n    // \u521d\u59cb\u5316\u5927\u9876\u5806\n    maxHeap := &intHeap{}\n    heap.Init(maxHeap)\n    /* \u5143\u7d20\u5165\u5806 */\n    // \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u6dfb\u52a0\u5143\u7d20\n    heap.Push(maxHeap, 1)\n    heap.Push(maxHeap, 3)\n    heap.Push(maxHeap, 2)\n    heap.Push(maxHeap, 4)\n    heap.Push(maxHeap, 5)\n\n    /* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\n    top := maxHeap.Top()\n    fmt.Printf(\"\u5806\u9876\u5143\u7d20\u4e3a %d\\n\", top)\n\n    /* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n    // \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u79fb\u9664\u5143\u7d20\n    heap.Pop(maxHeap) // 5\n    heap.Pop(maxHeap) // 4\n    heap.Pop(maxHeap) // 3\n    heap.Pop(maxHeap) // 2\n    heap.Pop(maxHeap) // 1\n\n    /* \u83b7\u53d6\u5806\u5927\u5c0f */\n    size := len(*maxHeap)\n    fmt.Printf(\"\u5806\u5143\u7d20\u6570\u91cf\u4e3a %d\\n\", size)\n\n    /* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\n    isEmpty := len(*maxHeap) == 0\n    fmt.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\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\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\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nlet peek = max_heap.peek().unwrap();  // 5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nlet size = max_heap.len();\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = max_heap.is_empty();\n\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\u7684\u7d22\u5f15\u4e3a \\(2i + 1\\) \uff0c\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\u4e3a \\(2i + 2\\) \uff0c\u7236\u8282\u70b9\u7684\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\u7684\u7d22\u5f15\"\"\"\n    return 2 * i + 1\n\ndef right(self, i: int) -> int:\n    \"\"\"\u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n    return 2 * i + 2\n\ndef parent(self, i: int) -> int:\n    \"\"\"\u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n    return (i - 1) // 2  # \u5411\u4e0b\u6574\u9664\n
    my_heap.cpp
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint left(int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(int i) {\n    return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.java
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint left(int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(int i) {\n    return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.cs
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint Left(int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint Right(int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint Parent(int i) {\n    return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.go
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (h *maxHeap) left(i int) int {\n    return 2*i + 1\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (h *maxHeap) right(i int) int {\n    return 2*i + 2\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (h *maxHeap) parent(i int) int {\n    // \u5411\u4e0b\u6574\u9664\n    return (i - 1) / 2\n}\n
    my_heap.swift
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc left(i: Int) -> Int {\n    2 * i + 1\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc right(i: Int) -> Int {\n    2 * i + 2\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\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\u7684\u7d22\u5f15 */\n#left(i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n#right(i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n#parent(i) {\n    return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.ts
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nleft(i: number): number {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nright(i: number): number {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nparent(i: number): number {\n    return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.dart
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint _left(int i) {\n  return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint _right(int i) {\n  return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint _parent(int i) {\n  return (i - 1) ~/ 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.rs
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn left(i: usize) -> usize {\n    2 * i + 1\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn right(i: usize) -> usize {\n    2 * i + 2\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\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\u7684\u7d22\u5f15 */\nint left(MaxHeap *maxHeap, int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(MaxHeap *maxHeap, int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(MaxHeap *maxHeap, int i) {\n    return (i - 1) / 2;\n}\n
    my_heap.zig
    // \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15\nfn left(i: usize) usize {\n    return 2 * i + 1;\n}\n\n// \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\nfn right(i: usize) usize {\n    return 2 * i + 2;\n}\n\n// \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15\nfn parent(i: usize) usize {\n    // return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n    return @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\"\"\"\n    return self.max_heap[0]\n
    my_heap.cpp
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\n    return maxHeap[0];\n}\n
    my_heap.java
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\n    return maxHeap.get(0);\n}\n
    my_heap.cs
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint Peek() {\n    return maxHeap[0];\n}\n
    my_heap.go
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc (h *maxHeap) peek() any {\n    return h.data[0]\n}\n
    my_heap.swift
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc peek() -> Int {\n    maxHeap[0]\n}\n
    my_heap.js
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek() {\n    return this.#maxHeap[0];\n}\n
    my_heap.ts
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek(): number {\n    return this.maxHeap[0];\n}\n
    my_heap.dart
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\n  return _maxHeap[0];\n}\n
    my_heap.rs
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfn peek(&self) -> Option<i32> {\n    self.max_heap.first().copied()\n}\n
    my_heap.c
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek(MaxHeap *maxHeap) {\n    return maxHeap->data[0];\n}\n
    my_heap.zig
    // \u8bbf\u95ee\u5806\u9876\u5143\u7d20\nfn peek(self: *Self) T {\n    return self.max_heap.?.items[0];\n}  \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\n    self.max_heap.append(val)\n    # \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    self.sift_up(self.size() - 1)\n\ndef sift_up(self, i: int):\n    \"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\"\"\"\n    while True:\n        # \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        p = 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\n        if p < 0 or self.max_heap[i] <= self.max_heap[p]:\n            break\n        # \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, p)\n        # \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p\n
    my_heap.cpp
    /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.push_back(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap[i] <= maxHeap[p])\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(maxHeap[i], maxHeap[p]);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.java
    /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.add(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap.get(i) <= maxHeap.get(p))\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.cs
    /* \u5143\u7d20\u5165\u5806 */\nvoid Push(int val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.Add(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    SiftUp(Size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid SiftUp(int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap[i] <= maxHeap[p])\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        Swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.go
    /* \u5143\u7d20\u5165\u5806 */\nfunc (h *maxHeap) push(val any) {\n    // \u6dfb\u52a0\u8282\u70b9\n    h.data = append(h.data, val)\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    h.siftUp(len(h.data) - 1)\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc (h *maxHeap) siftUp(i int) {\n    for true {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        p := 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\n        if p < 0 || h.data[i].(int) <= h.data[p].(int) {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        h.swap(i, p)\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p\n    }\n}\n
    my_heap.swift
    /* \u5143\u7d20\u5165\u5806 */\nfunc push(val: Int) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.append(val)\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(i: size() - 1)\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc siftUp(i: Int) {\n    var i = i\n    while true {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        let 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\n        if p < 0 || maxHeap[i] <= maxHeap[p] {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i: i, j: p)\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p\n    }\n}\n
    my_heap.js
    /* \u5143\u7d20\u5165\u5806 */\npush(val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    this.#maxHeap.push(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    this.#siftUp(this.size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\n#siftUp(i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        const 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\n        if (p < 0 || this.#maxHeap[i] <= this.#maxHeap[p]) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.#swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.ts
    /* \u5143\u7d20\u5165\u5806 */\npush(val: number): void {\n    // \u6dfb\u52a0\u8282\u70b9\n    this.maxHeap.push(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    this.siftUp(this.size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nsiftUp(i: number): void {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        const 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\n        if (p < 0 || this.maxHeap[i] <= this.maxHeap[p]) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = 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\n  siftUp(size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\n  while (true) {\n    // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n    int 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\n    if (p < 0 || _maxHeap[i] <= _maxHeap[p]) {\n      break;\n    }\n    // \u4ea4\u6362\u4e24\u8282\u70b9\n    _swap(i, p);\n    // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n    i = p;\n  }\n}\n
    my_heap.rs
    /* \u5143\u7d20\u5165\u5806 */\nfn push(&mut self, val: i32) {\n    // \u6dfb\u52a0\u8282\u70b9\n    self.max_heap.push(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    self.sift_up(self.size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfn sift_up(&mut self, mut i: usize) {\n    loop {\n        // \u8282\u70b9 i \u5df2\u7ecf\u662f\u5806\u9876\u8282\u70b9\u4e86\uff0c\u7ed3\u675f\u5806\u5316\n        if i == 0 {\n            break;\n        }\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        let p = Self::parent(i);\n        // \u5f53\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\n        if self.max_heap[i] <= self.max_heap[p] {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = 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\n    if (maxHeap->size == MAX_SIZE) {\n        printf(\"heap is full!\");\n        return;\n    }\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap->data[maxHeap->size] = val;\n    maxHeap->size++;\n\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(maxHeap, maxHeap->size - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(MaxHeap *maxHeap, int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap->data[i] <= maxHeap->data[p]) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(maxHeap, i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.zig
    // \u5143\u7d20\u5165\u5806\nfn push(self: *Self, val: T) !void {\n    // \u6dfb\u52a0\u8282\u70b9\n    try self.max_heap.?.append(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    try self.siftUp(self.size() - 1);\n}  \n\n// \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\nfn siftUp(self: *Self, i_: usize) !void {\n    var i = i_;\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        var 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\n        if (p < 0 or self.max_heap.?.items[i] <= self.max_heap.?.items[p]) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        try self.swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = 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\n    if self.is_empty():\n        raise 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\n    self.swap(0, self.size() - 1)\n    # \u5220\u9664\u8282\u70b9\n    val = self.max_heap.pop()\n    # \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    self.sift_down(0)\n    # \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val\n\ndef sift_down(self, i: int):\n    \"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\"\"\"\n    while True:\n        # \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        l, r, ma = self.left(i), self.right(i), i\n        if l < self.size() and self.max_heap[l] > self.max_heap[ma]:\n            ma = l\n        if r < self.size() and self.max_heap[r] > self.max_heap[ma]:\n            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\n        if ma == i:\n            break\n        # \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, ma)\n        # \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n
    my_heap.cpp
    /* \u5143\u7d20\u51fa\u5806 */\nvoid pop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (isEmpty()) {\n        throw 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\n    swap(maxHeap[0], maxHeap[size() - 1]);\n    // \u5220\u9664\u8282\u70b9\n    maxHeap.pop_back();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(0);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = left(i), r = right(i), ma = i;\n        if (l < size() && maxHeap[l] > maxHeap[ma])\n            ma = l;\n        if (r < size() && maxHeap[r] > maxHeap[ma])\n            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\n        if (ma == i)\n            break;\n        swap(maxHeap[i], maxHeap[ma]);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.java
    /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (isEmpty())\n        throw 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\n    swap(0, size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    int val = maxHeap.remove(size() - 1);\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = left(i), r = right(i), ma = i;\n        if (l < size() && maxHeap.get(l) > maxHeap.get(ma))\n            ma = l;\n        if (r < size() && maxHeap.get(r) > maxHeap.get(ma))\n            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\n        if (ma == i)\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.cs
    /* \u5143\u7d20\u51fa\u5806 */\nint Pop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (IsEmpty())\n        throw 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\n    Swap(0, Size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    int val = maxHeap.Last();\n    maxHeap.RemoveAt(Size() - 1);\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    SiftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid SiftDown(int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = Left(i), r = Right(i), ma = i;\n        if (l < Size() && maxHeap[l] > maxHeap[ma])\n            ma = l;\n        if (r < Size() && maxHeap[r] > maxHeap[ma])\n            ma = r;\n        // \u82e5\u201c\u8282\u70b9 i \u6700\u5927\u201d\u6216\u201c\u8d8a\u8fc7\u53f6\u8282\u70b9\u201d\uff0c\u5219\u7ed3\u675f\u5806\u5316\n        if (ma == i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        Swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.go
    /* \u5143\u7d20\u51fa\u5806 */\nfunc (h *maxHeap) pop() any {\n    // \u5224\u7a7a\u5904\u7406\n    if h.isEmpty() {\n        fmt.Println(\"error\")\n        return 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\n    h.swap(0, h.size()-1)\n    // \u5220\u9664\u8282\u70b9\n    val := h.data[len(h.data)-1]\n    h.data = h.data[:len(h.data)-1]\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    h.siftDown(0)\n\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc (h *maxHeap) siftDown(i int) {\n    for true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\n        l, r, max := h.left(i), h.right(i), i\n        if l < h.size() && h.data[l].(int) > h.data[max].(int) {\n            max = l\n        }\n        if r < h.size() && h.data[r].(int) > h.data[max].(int) {\n            max = 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\n        if max == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        h.swap(i, max)\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = max\n    }\n}\n
    my_heap.swift
    /* \u5143\u7d20\u51fa\u5806 */\nfunc pop() -> Int {\n    // \u5224\u7a7a\u5904\u7406\n    if isEmpty() {\n        fatalError(\"\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\n    swap(i: 0, j: size() - 1)\n    // \u5220\u9664\u8282\u70b9\n    let val = maxHeap.remove(at: size() - 1)\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(i: 0)\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(i: Int) {\n    var i = i\n    while true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = left(i: i)\n        let r = right(i: i)\n        var ma = i\n        if l < size(), maxHeap[l] > maxHeap[ma] {\n            ma = l\n        }\n        if r < size(), maxHeap[r] > maxHeap[ma] {\n            ma = 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\n        if ma == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i: i, j: ma)\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n    }\n}\n
    my_heap.js
    /* \u5143\u7d20\u51fa\u5806 */\npop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (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\n    this.#swap(0, this.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    const val = this.#maxHeap.pop();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    this.#siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\n#siftDown(i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        const l = this.#left(i),\n            r = this.#right(i);\n        let ma = i;\n        if (l < this.size() && this.#maxHeap[l] > this.#maxHeap[ma]) ma = l;\n        if (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\n        if (ma === i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.#swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.ts
    /* \u5143\u7d20\u51fa\u5806 */\npop(): number {\n    // \u5224\u7a7a\u5904\u7406\n    if (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\n    this.swap(0, this.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    const val = this.maxHeap.pop();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    this.siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nsiftDown(i: number): void {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        const l = this.left(i),\n            r = this.right(i);\n        let ma = i;\n        if (l < this.size() && this.maxHeap[l] > this.maxHeap[ma]) ma = l;\n        if (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\n        if (ma === i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.dart
    /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n  // \u5224\u7a7a\u5904\u7406\n  if (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\n  int val = _maxHeap.removeLast();\n  // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n  siftDown(0);\n  // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n  return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\n  while (true) {\n    // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n    int l = _left(i);\n    int r = _right(i);\n    int ma = i;\n    if (l < size() && _maxHeap[l] > _maxHeap[ma]) ma = l;\n    if (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\n    if (ma == i) break;\n    // \u4ea4\u6362\u4e24\u8282\u70b9\n    _swap(i, ma);\n    // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n    i = ma;\n  }\n}\n
    my_heap.rs
    /* \u5143\u7d20\u51fa\u5806 */\nfn pop(&mut self) -> i32 {\n    // \u5224\u7a7a\u5904\u7406\n    if self.is_empty() {\n        panic!(\"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\n    self.swap(0, self.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    let val = self.max_heap.remove(self.size() - 1);\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    self.sift_down(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    val\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfn sift_down(&mut self, mut i: usize) {\n    loop {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let (l, r, mut ma) = (Self::left(i), Self::right(i), i);\n        if l < self.size() && self.max_heap[l] > self.max_heap[ma] {\n            ma = l;\n        }\n        if r < self.size() && self.max_heap[r] > self.max_heap[ma] {\n            ma = 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\n        if ma == i {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.c
    /* \u5143\u7d20\u51fa\u5806 */\nint pop(MaxHeap *maxHeap) {\n    // \u5224\u7a7a\u5904\u7406\n    if (isEmpty(maxHeap)) {\n        printf(\"heap is empty!\");\n        return 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\n    swap(maxHeap, 0, size(maxHeap) - 1);\n    // \u5220\u9664\u8282\u70b9\n    int val = maxHeap->data[maxHeap->size - 1];\n    maxHeap->size--;\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(maxHeap, 0);\n\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(MaxHeap *maxHeap, int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\n        int l = left(maxHeap, i);\n        int r = right(maxHeap, i);\n        int max = i;\n        if (l < size(maxHeap) && maxHeap->data[l] > maxHeap->data[max]) {\n            max = l;\n        }\n        if (r < size(maxHeap) && maxHeap->data[r] > maxHeap->data[max]) {\n            max = 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\n        if (max == i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(maxHeap, i, max);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = max;\n    }\n}\n
    my_heap.zig
    // \u5143\u7d20\u51fa\u5806\nfn pop(self: *Self) !T {\n    // \u5224\u65ad\u5904\u7406\n    if (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\n    try self.swap(0, self.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    var val = self.max_heap.?.pop();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    try self.siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n} \n\n// \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\nfn siftDown(self: *Self, i_: usize) !void {\n    var i = i_;\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        var l = left(i);\n        var r = right(i);\n        var ma = i;\n        if (l < self.size() and self.max_heap.?.items[l] > self.max_heap.?.items[ma]) ma = l;\n        if (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\n        if (ma == i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        try self.swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    "},{"location":"chapter_heap/heap/#813","title":"8.1.3 \u00a0 \u5806\u7684\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\u201c\u5806\u201d\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\u6700\u5927\u7684 \\(k\\) \u4e2a\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\n    heap = []\n    # \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for i in range(k):\n        heapq.heappush(heap, nums[i])\n    # \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for 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\n        if nums[i] > heap[0]:\n            heapq.heappop(heap)\n            heapq.heappush(heap, nums[i])\n    return 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\n    priority_queue<int, vector<int>, greater<int>> heap;\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        heap.push(nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > heap.top()) {\n            heap.pop();\n            heap.push(nums[i]);\n        }\n    }\n    return 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\n    Queue<Integer> heap = new PriorityQueue<Integer>();\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        heap.offer(nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > heap.peek()) {\n            heap.poll();\n            heap.offer(nums[i]);\n        }\n    }\n    return 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\n    PriorityQueue<int, int> heap = new();\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        heap.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\n    for (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\n        if (nums[i] > heap.Peek()) {\n            heap.Dequeue();\n            heap.Enqueue(nums[i], nums[i]);\n        }\n    }\n    return 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\n    h := &minHeap{}\n    heap.Init(h)\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for i := 0; i < k; i++ {\n        heap.Push(h, nums[i])\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for 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\n        if nums[i] > h.Top().(int) {\n            heap.Pop(h)\n            heap.Push(h, nums[i])\n        }\n    }\n    return 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\n    var heap = Heap(nums.prefix(k))\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for 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\n        if nums[i] > heap.min()! {\n            _ = heap.removeMin()\n            heap.insert(nums[i])\n        }\n    }\n    return heap.unordered\n}\n
    top_k.js
    /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap, val) {\n    // \u5143\u7d20\u53d6\u53cd\n    maxHeap.push(-val);\n}\n\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.pop();\n}\n\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.peek();\n}\n\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return maxHeap.getMaxHeap().map((num) => -num);\n}\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\n    const maxHeap = new MaxHeap([]);\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (let i = 0; i < k; i++) {\n        pushMinHeap(maxHeap, nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > peekMinHeap(maxHeap)) {\n            popMinHeap(maxHeap);\n            pushMinHeap(maxHeap, nums[i]);\n        }\n    }\n    // \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\n    return getMinHeap(maxHeap);\n}\n
    top_k.ts
    /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap: MaxHeap, val: number): void {\n    // \u5143\u7d20\u53d6\u53cd\n    maxHeap.push(-val);\n}\n\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap: MaxHeap): number {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.pop();\n}\n\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap: MaxHeap): number {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.peek();\n}\n\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap: MaxHeap): number[] {\n    // \u5143\u7d20\u53d6\u53cd\n    return maxHeap.getMaxHeap().map((num: number) => -num);\n}\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\n    const maxHeap = new MaxHeap([]);\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (let i = 0; i < k; i++) {\n        pushMinHeap(maxHeap, nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > peekMinHeap(maxHeap)) {\n            popMinHeap(maxHeap);\n            pushMinHeap(maxHeap, nums[i]);\n        }\n    }\n    // \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\n    return 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\n  MinHeap 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\n  for (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\n    if (nums[i] > heap.peek()) {\n      heap.pop();\n      heap.push(nums[i]);\n    }\n  }\n  return 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\n    let mut heap = BinaryHeap::<Reverse<i32>>::new();\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for &num in nums.iter().take(k) {\n        heap.push(Reverse(num));\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for &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\n        if num > heap.peek().unwrap().0 {\n            heap.pop();\n            heap.push(Reverse(num));\n        }\n    }\n    heap\n}\n
    top_k.c
    /* \u5143\u7d20\u5165\u5806 */\nvoid pushMinHeap(MaxHeap *maxHeap, int val) {\n    // \u5143\u7d20\u53d6\u53cd\n    push(maxHeap, -val);\n}\n\n/* \u5143\u7d20\u51fa\u5806 */\nint popMinHeap(MaxHeap *maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -pop(maxHeap);\n}\n\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peekMinHeap(MaxHeap *maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -peek(maxHeap);\n}\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\n    int *res = (int *)malloc(maxHeap->size * sizeof(int));\n    for (int i = 0; i < maxHeap->size; i++) {\n        res[i] = -maxHeap->data[i];\n    }\n    return res;\n}\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\n    int *res = (int *)malloc(maxHeap->size * sizeof(int));\n    for (int i = 0; i < maxHeap->size; i++) {\n        res[i] = -maxHeap->data[i];\n    }\n    return res;\n}\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\n    int *empty = (int *)malloc(0);\n    MaxHeap *maxHeap = newMaxHeap(empty, 0);\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        pushMinHeap(maxHeap, nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > peekMinHeap(maxHeap)) {\n            popMinHeap(maxHeap);\n            pushMinHeap(maxHeap, nums[i]);\n        }\n    }\n    int *res = getMinHeap(maxHeap);\n    // \u91ca\u653e\u5185\u5b58\n    delMaxHeap(maxHeap);\n    return 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\u7684 \\(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\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\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\u5bf9\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\uff0c\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 \u548c Zig \u7b49\u8bed\u8a00\u3002
    • \u9f13\u52b1\u8bfb\u8005\u5728\u7ebf\u4e0a\u7ae0\u8282\u8bc4\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\u7684\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\u201c\u5927\u795e\u201d\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\u548c\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\u548c\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":"

    \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\uff09\uff1akrahets\u3001codingonion\u3001nuomi1\u3001Gonglja\u3001Reanon\u3001justin-tse\u3001danielsss\u3001hpstory\u3001S-N-O-R-L-A-X\u3001night-cruise\u3001msk397\u3001gvenusleo\u3001RiverTwilight\u3001gyt95\u3001zhuoqinyue\u3001Zuoxun\u3001Xia-Sang\u3001mingXta\u3001FangYuan33\u3001GN-Yu\u3001IsChristina\u3001xBLACKICEx\u3001guowei-gong\u3001Cathay-Chen\u3001mgisr\u3001JoseHung\u3001qualifier1024\u3001pengchzn\u3001Guanngxu\u3001longsizhuo\u3001L-Super\u3001what-is-me\u3001yuan0221\u3001lhxsm\u3001Slone123c\u3001WSL0809\u3001longranger2\u3001theNefelibatas\u3001xiongsp\u3001JeffersonHuang\u3001hongyun-robot\u3001K3v123\u3001yuelinxin\u3001a16su\u3001gaofer\u3001malone6\u3001Wonderdch\u3001xjr7670\u3001DullSword\u3001Horbin-Magician\u3001NI-SW\u3001reeswell\u3001XC-Zero\u3001XiaChuerwu\u3001yd-j\u3001iron-irax\u3001huawuque404\u3001MolDuM\u3001Nigh\u3001KorsChen\u3001foursevenlove\u300152coder\u3001bubble9um\u3001youshaoXG\u3001curly210102\u3001gltianwen\u3001fanchenggang\u3001Transmigration-zhou\u3001FloranceYeh\u3001FreddieLi\u3001ShiMaRing\u3001lipusheng\u3001Javesun99\u3001JackYang-hellobobo\u3001shanghai-Jerry\u30010130w\u3001Keynman\u3001psychelzh\u3001logan-qiu\u3001ZnYang2018\u3001MwumLi\u30011ch0\u3001Phoenix0415\u3001qingpeng9802\u3001Richard-Zhang1019\u3001QiLOL\u3001Suremotoo\u3001Turing-1024-Lee\u3001Evilrabbit520\u3001GaochaoZhu\u3001ZJKung\u3001linzeyan\u3001hezhizhen\u3001ZongYangL\u3001beintentional\u3001czruby\u3001coderlef\u3001dshlstarr\u3001szu17dmy\u3001fbigm\u3001gledfish\u3001hts0000\u3001boloboloda\u3001iStig\u3001jiaxianhua\u3001wenjianmin\u3001keshida\u3001kilikilikid\u3001lclc6\u3001lwbaptx\u3001liuxjerry\u3001lucaswangdev\u3001lyl625760\u3001chadyi\u3001noobcodemaker\u3001selear\u3001siqyka\u3001syd168\u30014yDX3906\u3001tao363\u3001wangwang105\u3001weibk\u3001yabo083\u3001yi427\u3001yishangzhang\u3001zhouLion\u3001baagod\u3001ElaBosak233\u3001xb534\u3001luluxia\u3001yanedie\u3001thomasq0 \u548c YangXuanyi\u3002

    \u672c\u4e66\u7684\u4ee3\u7801\u5ba1\u9605\u5de5\u4f5c\u7531 codingonion, Gonglja\u3001gvenusleo\u3001hpstory\u3001justin\u2010tse\u3001krahets\u3001night-cruise\u3001nuomi1 \u548c Reanon \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

    \u5728\u672c\u4e66\u7684\u521b\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u5f97\u5230\u4e86\u8bb8\u591a\u4eba\u7684\u5e2e\u52a9\u3002

    • \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\u5b8c\u5584\u8d77\u5230\u4e86\u91cd\u8981\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\u7684\u9a71\u4f7f\u4e0b\u591a\u6b21\u8010\u5fc3\u4fee\u6539\uff1b
    • \u611f\u8c22 @squidfunk \u63d0\u4f9b\u7684\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\u6211\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 \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 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\n# \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\u4ee5\u56fe\u89e3\u5f62\u5f0f\u5c55\u793a\uff0c\u800c\u6587\u5b57\u5219\u4f5c\u4e3a\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\u7f51\u9875\u7248\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\u4f60\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\u548c\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\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\u8bc4\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\n    i, 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\n    while 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\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        elif nums[m] > target:\n            j = m - 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        else:\n            return m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    i, 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\n    for i <= j {\n        m := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i = 0\n    var 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\n    while i <= j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    let i = 0,\n        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\n    while (i <= j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\n        const m = parseInt(i + (j - i) / 2);\n        if (nums[m] < target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else 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\n    return -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\n    let i = 0,\n        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\n    while (i <= j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        const m = Math.floor(i + (j - i) / 2);\n        if (nums[m] < target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        } else if (nums[m] > target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        } else {\n            // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }\n    }\n    return -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\n  int 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\n  while (i <= j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n      i = m + 1;\n    } else if (nums[m] > target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n      j = m - 1;\n    } else {\n      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n      return m;\n    }\n  }\n  // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n  return -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\n    let mut i = 0;\n    let 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\n    while i <= j {\n        let m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        } else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        } else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }                       \n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i: usize = 0;\n    var 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\n    while (i <= j) {\n        var m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        } else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        } else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return @intCast(m);\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -1;\n}\n

    \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(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\u4e3a \\(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\n    i, 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\n    while i < j:\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n        elif nums[m] > target:\n            j = m  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n        else:\n            return m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    i, 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\n    for i < j {\n        m := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i = 0\n    var 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\n    while i < j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    let i = 0,\n        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\n    while (i < j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\n        const m = parseInt(i + (j - i) / 2);\n        if (nums[m] < target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        else return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    let i = 0,\n        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\n    while (i < j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        const m = Math.floor(i + (j - i) / 2);\n        if (nums[m] < target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        } else if (nums[m] > target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        } else {\n            // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }\n    }\n    return -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\n  int 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\n  while (i < j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n      i = m + 1;\n    } else if (nums[m] > target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n      j = m;\n    } else {\n      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n      return m;\n    }\n  }\n  // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n  return -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\n    let mut i = 0;\n    let 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\n    while i < j {\n        let m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        } else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        } else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }                       \n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i: usize = 0;\n    var 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\n    while (i <= j) {\n        var m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        } else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        } else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return @intCast(m);\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    i = binary_search_insertion(nums, target)\n    # \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == len(nums) or nums[i] != target:\n        return -1\n    # \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    int i = binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == nums.size() || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    int i = binary_search_insertion.binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == nums.length || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    int i = binary_search_insertion.BinarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == nums.Length || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    i := binarySearchInsertion(nums, target)\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == len(nums) || nums[i] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    let i = binarySearchInsertion(nums: nums, target: target)\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == nums.count || nums[i] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    const i = binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i === nums.length || nums[i] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    const i = binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i === nums.length || nums[i] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n  int i = binarySearchInsertion(nums, target);\n  // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n  if (i == nums.length || nums[i] != target) {\n    return -1;\n  }\n  // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n  return 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\n    let i = binary_search_insertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == nums.len() as i32 || nums[i as usize] != target {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    i\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\n    int i = binarySearchInsertion(nums, numSize, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == numSize || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    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\n    j = i - 1\n    # \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 or nums[j] != target:\n        return -1\n    # \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    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\n    j := i - 1\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 || nums[j] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    let 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\n    let j = i - 1\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 || nums[j] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    const 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\n    const j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j === -1 || nums[j] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    const 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\n    const j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j === -1 || nums[j] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n  int 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\n  int j = i - 1;\n  // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n  if (j == -1 || nums[j] != target) {\n    return -1;\n  }\n  // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n  return 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\n    let 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\n    let j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 || nums[j as usize] != target {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    j\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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\uff08Python \u65e0\u987b\u6539\u52a8\uff09\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\u793a\u4f8b\u5982\u56fe 10-4 \u6240\u793a\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\"\"\"\n    i, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j:\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        elif nums[m] > target:\n            j = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        else:\n            return m  # \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n    # \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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) {\n    int i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n    int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n    int i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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]\n    i, j := 0, len(nums)-1\n    for i <= j {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        m := i + (j-i)/2\n        if nums[m] < target {\n            // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target {\n            // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else {\n            // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n            return m\n        }\n    }\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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 {\n    var i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target {\n            i = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m] > target {\n            j = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return i;\n}\n
    binary_search_insertion.ts
    /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertionSimple(\n    nums: Array<number>,\n    target: number\n): number {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n  int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n  while (i <= j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n    } else if (nums[m] > target) {\n      j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n    } else {\n      return 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\n  return 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 {\n    let (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {\n            i = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m as usize] > target {\n            j = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    i\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) {\n    int i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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\"\"\"\n    i, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j:\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        elif nums[m] > target:\n            j = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        else:\n            j = m - 1  # \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n    # \u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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) {\n    int i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n    int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n    int i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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]\n    i, j := 0, len(nums)-1\n    for i <= j {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        m := i + (j-i)/2\n        if nums[m] < target {\n            // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target {\n            // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else {\n            // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        }\n    }\n    // \u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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 {\n    var i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target {\n            i = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m] > target {\n            j = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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 {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n  int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n  while (i <= j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n    } else if (nums[m] > target) {\n      j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n    } else {\n      j = 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\n  return 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 {\n    let (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {\n            i = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m as usize] > target {\n            j = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    i\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) {\n    int i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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)\n    for i in range(len(nums) - 1):\n        for j in range(i + 1, len(nums)):\n            if nums[i] + nums[j] == target:\n                return [i, j]\n    return []\n
    two_sum.cpp
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nvector<int> twoSumBruteForce(vector<int> &nums, int target) {\n    int size = nums.size();\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (int i = 0; i < size - 1; i++) {\n        for (int j = i + 1; j < size; j++) {\n            if (nums[i] + nums[j] == target)\n                return {i, j};\n        }\n    }\n    return {};\n}\n
    two_sum.java
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] twoSumBruteForce(int[] nums, int target) {\n    int size = nums.length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (int i = 0; i < size - 1; i++) {\n        for (int j = i + 1; j < size; j++) {\n            if (nums[i] + nums[j] == target)\n                return new int[] { i, j };\n        }\n    }\n    return new int[0];\n}\n
    two_sum.cs
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] TwoSumBruteForce(int[] nums, int target) {\n    int size = nums.Length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (int i = 0; i < size - 1; i++) {\n        for (int j = i + 1; j < size; j++) {\n            if (nums[i] + nums[j] == target)\n                return [i, j];\n        }\n    }\n    return [];\n}\n
    two_sum.go
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunc twoSumBruteForce(nums []int, target int) []int {\n    size := len(nums)\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for i := 0; i < size-1; i++ {\n        for j := i + 1; i < size; j++ {\n            if nums[i]+nums[j] == target {\n                return []int{i, j}\n            }\n        }\n    }\n    return 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)\n    for i in nums.indices.dropLast() {\n        for j in nums.indices.dropFirst(i + 1) {\n            if nums[i] + nums[j] == target {\n                return [i, j]\n            }\n        }\n    }\n    return [0]\n}\n
    two_sum.js
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums, target) {\n    const n = nums.length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (let i = 0; i < n; i++) {\n        for (let j = i + 1; j < n; j++) {\n            if (nums[i] + nums[j] === target) {\n                return [i, j];\n            }\n        }\n    }\n    return [];\n}\n
    two_sum.ts
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums: number[], target: number): number[] {\n    const n = nums.length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (let i = 0; i < n; i++) {\n        for (let j = i + 1; j < n; j++) {\n            if (nums[i] + nums[j] === target) {\n                return [i, j];\n            }\n        }\n    }\n    return [];\n}\n
    two_sum.dart
    /* \u65b9\u6cd5\u4e00\uff1a \u66b4\u529b\u679a\u4e3e */\nList<int> twoSumBruteForce(List<int> nums, int target) {\n  int size = nums.length;\n  // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n  for (var i = 0; i < size - 1; i++) {\n    for (var j = i + 1; j < size; j++) {\n      if (nums[i] + nums[j] == target) return [i, j];\n    }\n  }\n  return [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>> {\n    let size = nums.len();\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for i in 0..size - 1 {\n        for j in i + 1..size {\n            if nums[i] + nums[j] == target {\n                return Some(vec![i as i32, j as i32]);\n            }\n        }\n    }\n    None\n}\n
    two_sum.c
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {\n    for (int i = 0; i < numsSize; ++i) {\n        for (int j = i + 1; j < numsSize; ++j) {\n            if (nums[i] + nums[j] == target) {\n                int *res = malloc(sizeof(int) * 2);\n                res[0] = i, res[1] = j;\n                *returnSize = 2;\n                return res;\n            }\n        }\n    }\n    *returnSize = 0;\n    return NULL;\n}\n
    two_sum.zig
    // \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e\nfn twoSumBruteForce(nums: []i32, target: i32) ?[2]i32 {\n    var size: usize = nums.len;\n    var i: usize = 0;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    while (i < size - 1) : (i += 1) {\n        var j = i + 1;\n        while (j < size) : (j += 1) {\n            if (nums[i] + nums[j] == target) {\n                return [_]i32{@intCast(i), @intCast(j)};\n            }\n        }\n    }\n    return 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)\n    dic = {}\n    # \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for i in range(len(nums)):\n        if target - nums[i] in dic:\n            return [dic[target - nums[i]], i]\n        dic[nums[i]] = i\n    return []\n
    two_sum.cpp
    /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nvector<int> twoSumHashTable(vector<int> &nums, int target) {\n    int size = nums.size();\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    unordered_map<int, int> dic;\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (int i = 0; i < size; i++) {\n        if (dic.find(target - nums[i]) != dic.end()) {\n            return {dic[target - nums[i]], i};\n        }\n        dic.emplace(nums[i], i);\n    }\n    return {};\n}\n
    two_sum.java
    /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] twoSumHashTable(int[] nums, int target) {\n    int size = nums.length;\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    Map<Integer, Integer> dic = new HashMap<>();\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (int i = 0; i < size; i++) {\n        if (dic.containsKey(target - nums[i])) {\n            return new int[] { dic.get(target - nums[i]), i };\n        }\n        dic.put(nums[i], i);\n    }\n    return new int[0];\n}\n
    two_sum.cs
    /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] TwoSumHashTable(int[] nums, int target) {\n    int size = nums.Length;\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    Dictionary<int, int> dic = [];\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (int i = 0; i < size; i++) {\n        if (dic.ContainsKey(target - nums[i])) {\n            return [dic[target - nums[i]], i];\n        }\n        dic.Add(nums[i], i);\n    }\n    return [];\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)\n    hashTable := map[int]int{}\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for idx, val := range nums {\n        if preIdx, ok := hashTable[target-val]; ok {\n            return []int{preIdx, idx}\n        }\n        hashTable[val] = idx\n    }\n    return 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)\n    var dic: [Int: Int] = [:]\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for i in nums.indices {\n        if let j = dic[target - nums[i]] {\n            return [j, i]\n        }\n        dic[nums[i]] = i\n    }\n    return [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)\n    let m = {};\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (let i = 0; i < nums.length; i++) {\n        if (m[target - nums[i]] !== undefined) {\n            return [m[target - nums[i]], i];\n        } else {\n            m[nums[i]] = i;\n        }\n    }\n    return [];\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)\n    let m: Map<number, number> = new Map();\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (let i = 0; i < nums.length; i++) {\n        let index = m.get(target - nums[i]);\n        if (index !== undefined) {\n            return [index, i];\n        } else {\n            m.set(nums[i], i);\n        }\n    }\n    return [];\n}\n
    two_sum.dart
    /* \u65b9\u6cd5\u4e8c\uff1a \u8f85\u52a9\u54c8\u5e0c\u8868 */\nList<int> twoSumHashTable(List<int> nums, int target) {\n  int size = nums.length;\n  // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n  Map<int, int> dic = HashMap();\n  // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n  for (var i = 0; i < size; i++) {\n    if (dic.containsKey(target - nums[i])) {\n      return [dic[target - nums[i]]!, i];\n    }\n    dic.putIfAbsent(nums[i], () => i);\n  }\n  return [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)\n    let mut dic = HashMap::new();\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (i, num) in nums.iter().enumerate() {\n        match dic.get(&(target - num)) {\n            Some(v) => return Some(vec![*v as i32, i as i32]),\n            None => dic.insert(num, i as i32)\n        };\n    }\n    None\n}\n
    two_sum.c
    /* \u54c8\u5e0c\u8868 */\ntypedef struct {\n    int key;\n    int val;\n    UT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n\n/* \u54c8\u5e0c\u8868\u67e5\u8be2 */\nHashTable *find(HashTable *h, int key) {\n    HashTable *tmp;\n    HASH_FIND_INT(h, &key, tmp);\n    return tmp;\n}\n\n/* \u54c8\u5e0c\u8868\u5143\u7d20\u63d2\u5165 */\nvoid insert(HashTable *h, int key, int val) {\n    HashTable *t = find(h, key);\n    if (t == NULL) {\n        HashTable *tmp = malloc(sizeof(HashTable));\n        tmp->key = key, tmp->val = val;\n        HASH_ADD_INT(h, key, tmp);\n    } else {\n        t->val = val;\n    }\n}\n\n/* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint *twoSumHashTable(int *nums, int numsSize, int target, int *returnSize) {\n    HashTable *hashtable = NULL;\n    for (int i = 0; i < numsSize; i++) {\n        HashTable *t = find(hashtable, target - nums[i]);\n        if (t != NULL) {\n            int *res = malloc(sizeof(int) * 2);\n            res[0] = t->val, res[1] = i;\n            *returnSize = 2;\n            return res;\n        }\n        insert(hashtable, nums[i], i);\n    }\n    *returnSize = 0;\n    return NULL;\n}\n
    two_sum.zig
    // \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868\nfn twoSumHashTable(nums: []i32, target: i32) !?[2]i32 {\n    var size: usize = nums.len;\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    var dic = std.AutoHashMap(i32, i32).init(std.heap.page_allocator);\n    defer dic.deinit();\n    var i: usize = 0;\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    while (i < size) : (i += 1) {\n        if (dic.contains(target - nums[i])) {\n            return [_]i32{dic.get(target - nums[i]).?, @intCast(i)};\n        }\n        try dic.put(nums[i], @intCast(i));\n    }\n    return 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\u7684\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\u3002
    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\"\"\"\n    n = len(nums)\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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\n        for j in range(i):\n            if nums[j] > nums[j + 1]:\n                # \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[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]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                // \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\n                swap(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]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    for (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 \n        for (int j = 0; j < i; j++) {\n            if (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]\n    for 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\n        for j := 0; j < i; j++ {\n            if nums[j] > nums[j+1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[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]\n    for 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 \n        for j in stride(from: 0, to: i, by: 1) {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j]\n                nums[j] = nums[j + 1]\n                nums[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]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n  for (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\n    for (int j = 0; j < i; j++) {\n      if (nums[j] > nums[j + 1]) {\n        // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n        int tmp = nums[j];\n        nums[j] = nums[j + 1];\n        nums[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]\n    for 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 \n        for j in 0..i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    for (int i = 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                int temp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    var i: usize = nums.len - 1;\n    while (i > 0) : (i -= 1) {\n        var 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 \n        while (j < i) : (j += 1) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                var tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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\"\"\"\n    n = len(nums)\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for i in range(n - 1, 0, -1):\n        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\n        for j in range(i):\n            if nums[j] > nums[j + 1]:\n                # \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[j], nums[j + 1] = nums[j + 1], nums[j]\n                flag = True  # \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n        if not flag:\n            break  # \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = nums.size() - 1; i > 0; i--) {\n        bool 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                // \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\n                swap(nums[j], nums[j + 1]);\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag)\n            break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = nums.length - 1; i > 0; i--) {\n        boolean 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag)\n            break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = nums.Length - 1; i > 0; i--) {\n        bool 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 \n        for (int j = 0; j < i; j++) {\n            if (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                flag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag) break;     // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for i := len(nums) - 1; i > 0; i-- {\n        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\n        for j := 0; j < i; j++ {\n            if nums[j] > nums[j+1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[j], nums[j+1] = nums[j+1], nums[j]\n                flag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if flag == false { // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n            break\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]\n    for i in stride(from: nums.count - 1, to: 0, by: -1) {\n        var flag = false // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n        for j in stride(from: 0, to: i, by: 1) {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j]\n                nums[j] = nums[j + 1]\n                nums[j + 1] = tmp\n                flag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if !flag { // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n            break\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]\n    for (let i = nums.length - 1; i > 0; i--) {\n        let 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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag) break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (let i = nums.length - 1; i > 0; i--) {\n        let 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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag) break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n  for (int i = nums.length - 1; i > 0; i--) {\n    bool 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\n    for (int j = 0; j < i; j++) {\n      if (nums[j] > nums[j + 1]) {\n        // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n        int tmp = nums[j];\n        nums[j] = nums[j + 1];\n        nums[j + 1] = tmp;\n        flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n      }\n    }\n    if (!flag) break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for i in (1..nums.len()).rev() {\n        let 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 \n        for j in 0..i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if !flag {break};  // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = size - 1; i > 0; i--) {\n        bool 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                int temp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = temp;\n                flag = true;\n            }\n        }\n        if (!flag)\n            break;\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]\n    var i: usize = nums.len - 1;\n    while (i > 0) : (i -= 1) {\n        var flag = false;   // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n        var 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 \n        while (j < i) : (j += 1) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                var tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true;\n            }\n        }\n        if (!flag) break;   // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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\n    k = len(nums) // 2\n    buckets = [[] for _ in range(k)]\n    # 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for 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]\n        i = int(num * k)\n        # \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].append(num)\n    # 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        bucket.sort()\n    # 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    i = 0\n    for bucket in buckets:\n        for num in bucket:\n            nums[i] = num\n            i += 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\n    int k = nums.size() / 2;\n    vector<vector<float>> buckets(k);\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        int i = num * k;\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\n        buckets[i].push_back(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        sort(bucket.begin(), bucket.end());\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    int i = 0;\n    for (vector<float> &bucket : buckets) {\n        for (float num : bucket) {\n            nums[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\n    int k = nums.length / 2;\n    List<List<Float>> buckets = new ArrayList<>();\n    for (int i = 0; i < k; i++) {\n        buckets.add(new ArrayList<>());\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        int i = (int) (num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets.get(i).add(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        Collections.sort(bucket);\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    int i = 0;\n    for (List<Float> bucket : buckets) {\n        for (float num : bucket) {\n            nums[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\n    int k = nums.Length / 2;\n    List<List<float>> buckets = [];\n    for (int i = 0; i < k; i++) {\n        buckets.Add([]);\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    foreach (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]\n        int i = (int)(num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].Add(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    foreach (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\n        bucket.Sort();\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    int j = 0;\n    foreach (List<float> bucket in buckets) {\n        foreach (float num in bucket) {\n            nums[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\n    k := len(nums) / 2\n    buckets := make([][]float64, k)\n    for i := 0; i < k; i++ {\n        buckets[i] = make([]float64, 0)\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for _, 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]\n        i := int(num * float64(k))\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i] = append(buckets[i], num)\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        sort.Float64s(buckets[i])\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    i := 0\n    for _, bucket := range buckets {\n        for _, num := range bucket {\n            nums[i] = num\n            i++\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\n    let k = nums.count / 2\n    var buckets = (0 ..< k).map { _ in [Double]() }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for 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]\n        let i = Int(num * Double(k))\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].append(num)\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        buckets[i].sort()\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    var i = nums.startIndex\n    for bucket in buckets {\n        for num in bucket {\n            nums[i] = num\n            nums.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\n    const k = nums.length / 2;\n    const buckets = [];\n    for (let i = 0; i < k; i++) {\n        buckets.push([]);\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        const i = Math.floor(num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].push(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        bucket.sort((a, b) => a - b);\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    let i = 0;\n    for (const bucket of buckets) {\n        for (const num of bucket) {\n            nums[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\n    const k = nums.length / 2;\n    const buckets: number[][] = [];\n    for (let i = 0; i < k; i++) {\n        buckets.push([]);\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        const i = Math.floor(num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].push(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        bucket.sort((a, b) => a - b);\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    let i = 0;\n    for (const bucket of buckets) {\n        for (const num of bucket) {\n            nums[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\n  int k = nums.length ~/ 2;\n  List<List<double>> buckets = List.generate(k, (index) => []);\n\n  // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n  for (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]\n    int i = (_num * k).toInt();\n    // \u5c06 _num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\n    buckets[i].add(_num);\n  }\n  // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n  for (List<double> bucket in buckets) {\n    bucket.sort();\n  }\n  // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n  int i = 0;\n  for (List<double> bucket in buckets) {\n    for (double _num in bucket) {\n      nums[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\n    let k = nums.len() / 2;\n    let mut buckets = vec![vec![]; k];\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for &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]\n        let i = (num * k as f64) as usize;\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].push(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        bucket.sort_by(|a, b| a.partial_cmp(b).unwrap());\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    let mut i = 0;\n    for bucket in &mut buckets {\n        for &mut num in bucket {\n            nums[i] = num;\n            i += 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\n    int k = size / 2;\n    float **buckets = calloc(k, sizeof(float *));\n    for (int i = 0; i < k; i++) {\n        // \u6bcf\u4e2a\u6876\u6700\u591a\u53ef\u4ee5\u5206\u914d k \u4e2a\u5143\u7d20\n        buckets[i] = calloc(ARRAY_SIZE, sizeof(float));\n    }\n\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        int bucket_idx = nums[i] * k;\n        int 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\n        while (buckets[bucket_idx][j] > 0 && buckets[bucket_idx][j] < nums[i]) {\n            j++;\n        }\n        float temp = nums[i];\n        while (j < ARRAY_SIZE && buckets[bucket_idx][j] > 0) {\n            swap(&temp, &buckets[bucket_idx][j]);\n            j++;\n        }\n        buckets[bucket_idx][j] = temp;\n    }\n\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (int i = 0; i < k; i++) {\n        qsort(buckets[i], ARRAY_SIZE, sizeof(float), compare_float);\n    }\n\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    for (int i = 0, j = 0; j < k; j++) {\n        for (int l = 0; l < ARRAY_SIZE; l++) {\n            if (buckets[j][l] > 0) {\n                nums[i++] = buckets[j][l];\n            }\n        }\n    }\n\n    // \u91ca\u653e\u4e0a\u8ff0\u5206\u914d\u7684\u5185\u5b58\n    for (int i = 0; i < k; i++) {\n        free(buckets[i]);\n    }\n    free(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\u4e3a \\(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\u4e3a \\(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\n    m = 0\n    for num in nums:\n        m = 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\n    counter = [0] * (m + 1)\n    for num in nums:\n        counter[num] += 1\n    # 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    i = 0\n    for num in range(m + 1):\n        for _ in range(counter[num]):\n            nums[i] = num\n            i += 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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    vector<int> counter(m + 1, 0);\n    for (int num : nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    for (int num : nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    int m = 0;\n    foreach (int num in nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    foreach (int num in nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    m := 0\n    for _, num := range nums {\n        if num > m {\n            m = 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\n    counter := make([]int, m+1)\n    for _, num := range nums {\n        counter[num]++\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    for i, num := 0, 0; num < m+1; num++ {\n        for j := 0; j < counter[num]; j++ {\n            nums[i] = num\n            i++\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\n    let 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\n    var counter = Array(repeating: 0, count: m + 1)\n    for num in nums {\n        counter[num] += 1\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    var i = 0\n    for num in stride(from: 0, to: m + 1, by: 1) {\n        for _ in stride(from: 0, to: counter[num], by: 1) {\n            nums[i] = num\n            i += 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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter = new Array(m + 1).fill(0);\n    for (const num of nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    let i = 0;\n    for (let num = 0; num < m + 1; num++) {\n        for (let j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter: number[] = new Array<number>(m + 1).fill(0);\n    for (const num of nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    let i = 0;\n    for (let num = 0; num < m + 1; num++) {\n        for (let j = 0; j < counter[num]; j++, i++) {\n            nums[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\n  int m = 0;\n  for (int _num in nums) {\n    m = 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\n  List<int> counter = List.filled(m + 1, 0);\n  for (int _num in nums) {\n    counter[_num]++;\n  }\n  // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n  int i = 0;\n  for (int _num = 0; _num < m + 1; _num++) {\n    for (int j = 0; j < counter[_num]; j++, i++) {\n      nums[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\n    let 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\n    let mut counter = vec![0; m as usize + 1];\n    for &num in &*nums {\n        counter[num as usize] += 1;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    let mut i = 0;\n    for num in 0..m + 1 {\n        for _ in 0..counter[num as usize] {\n            nums[i] = num;\n            i += 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\n    int m = 0;\n    for (int i = 0; i < size; i++) {\n        if (nums[i] > m) {\n            m = 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\n    int *counter = calloc(m, sizeof(int));\n    for (int i = 0; i < size; i++) {\n        counter[nums[i]]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[i] = num;\n        }\n    }\n    // 4. \u91ca\u653e\u5185\u5b58\n    free(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\n    m = 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\n    counter = [0] * (m + 1)\n    for num in nums:\n        counter[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\n    for i in range(m):\n        counter[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\n    n = len(nums)\n    res = [0] * n\n    for i in range(n - 1, -1, -1):\n        num = nums[i]\n        res[counter[num] - 1] = num  # \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for i in range(n):\n        nums[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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    vector<int> counter(m + 1, 0);\n    for (int num : nums) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int n = nums.size();\n    vector<int> res(n);\n    for (int i = n - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    nums = 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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    for (int num : nums) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int n = nums.length;\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (int i = 0; i < n; i++) {\n        nums[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\n    int m = 0;\n    foreach (int num in nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    foreach (int num in nums) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int n = nums.Length;\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (int i = 0; i < n; i++) {\n        nums[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\n    m := 0\n    for _, num := range nums {\n        if num > m {\n            m = 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\n    counter := make([]int, m+1)\n    for _, num := range nums {\n        counter[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\n    for i := 0; i < m; i++ {\n        counter[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\n    n := len(nums)\n    res := make([]int, n)\n    for i := n - 1; i >= 0; i-- {\n        num := nums[i]\n        // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        res[counter[num]-1] = num\n        // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n        counter[num]--\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\n    copy(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\n    let 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\n    var counter = Array(repeating: 0, count: m + 1)\n    for num in nums {\n        counter[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\n    for i in stride(from: 0, to: m, by: 1) {\n        counter[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\n    var res = Array(repeating: 0, count: nums.count)\n    for i in stride(from: nums.count - 1, through: 0, by: -1) {\n        let num = nums[i]\n        res[counter[num] - 1] = num // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for i in stride(from: 0, to: nums.count, by: 1) {\n        nums[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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter = new Array(m + 1).fill(0);\n    for (const num of nums) {\n        counter[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\n    for (let i = 0; i < m; i++) {\n        counter[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\n    const n = nums.length;\n    const res = new Array(n);\n    for (let i = n - 1; i >= 0; i--) {\n        const num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (let i = 0; i < n; i++) {\n        nums[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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter: number[] = new Array<number>(m + 1).fill(0);\n    for (const num of nums) {\n        counter[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\n    for (let i = 0; i < m; i++) {\n        counter[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\n    const n = nums.length;\n    const res: number[] = new Array<number>(n);\n    for (let i = n - 1; i >= 0; i--) {\n        const num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (let i = 0; i < n; i++) {\n        nums[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\n  int m = 0;\n  for (int _num in nums) {\n    m = 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\n  List<int> counter = List.filled(m + 1, 0);\n  for (int _num in nums) {\n    counter[_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\n  for (int i = 0; i < m; i++) {\n    counter[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\n  int n = nums.length;\n  List<int> res = List.filled(n, 0);\n  for (int i = n - 1; i >= 0; i--) {\n    int _num = nums[i];\n    res[counter[_num] - 1] = _num; // \u5c06 _num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n    counter[_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\n  nums.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\n    let 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\n    let mut counter = vec![0; m as usize + 1];\n    for &num in &*nums {\n        counter[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\n    for i in 0..m as usize {\n        counter[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\n    let n = nums.len();\n    let mut res = vec![0; n];\n    for i in (0..n).rev() {\n        let num = nums[i];\n        res[counter[num as usize] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for i in 0..n {\n        nums[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\n    int m = 0;\n    for (int i = 0; i < size; i++) {\n        if (nums[i] > m) {\n            m = 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\n    int *counter = calloc(m, sizeof(int));\n    for (int i = 0; i < size; i++) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int *res = malloc(sizeof(int) * size);\n    for (int i = size - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    memcpy(nums, res, size * sizeof(int));\n    // 5. \u91ca\u653e\u5185\u5b58\n    free(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\u4e3a \\(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\u4e3a \\(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\"\"\"\n    while True:\n        # \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        l = 2 * i + 1\n        r = 2 * i + 2\n        ma = i\n        if l < n and nums[l] > nums[ma]:\n            ma = l\n        if r < n and nums[r] > nums[ma]:\n            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\n        if ma == i:\n            break\n        # \u4ea4\u6362\u4e24\u8282\u70b9\n        nums[i], nums[ma] = nums[ma], nums[i]\n        # \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n\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\n    for i in range(len(nums) // 2 - 1, -1, -1):\n        sift_down(nums, len(nums), i)\n    # \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\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\n        sift_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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(nums[i], nums[ma]);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = nums.size() / 2 - 1; i >= 0; --i) {\n        siftDown(nums, nums.size(), i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        swap(nums[0], nums[i]);\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i)\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        int temp = nums[i];\n        nums[i] = nums[ma];\n        nums[ma] = temp;\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = nums.length / 2 - 1; i >= 0; i--) {\n        siftDown(nums, nums.length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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        int tmp = nums[0];\n        nums[0] = nums[i];\n        nums[i] = tmp;\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i)\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        (nums[ma], nums[i]) = (nums[i], nums[ma]);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = nums.Length / 2 - 1; i >= 0; i--) {\n        SiftDown(nums, nums.Length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        SiftDown(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) {\n    for true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        l := 2*i + 1\n        r := 2*i + 2\n        ma := i\n        if l < n && (*nums)[l] > (*nums)[ma] {\n            ma = l\n        }\n        if r < n && (*nums)[r] > (*nums)[ma] {\n            ma = 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\n        if ma == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        (*nums)[i], (*nums)[ma] = (*nums)[ma], (*nums)[i]\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n    }\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\n    for i := len(*nums)/2 - 1; i >= 0; i-- {\n        siftDown(nums, len(*nums), i)\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\n        siftDown(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) {\n    var i = i\n    while true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1\n        let r = 2 * i + 2\n        var ma = i\n        if l < n, nums[l] > nums[ma] {\n            ma = l\n        }\n        if r < n, nums[r] > nums[ma] {\n            ma = 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\n        if ma == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        nums.swapAt(i, ma)\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n    }\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\n    for i in stride(from: nums.count / 2 - 1, through: 0, by: -1) {\n        siftDown(nums: &nums, n: nums.count, i: i)\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\n        nums.swapAt(0, i)\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1;\n        let r = 2 * i + 2;\n        let ma = i;\n        if (l < n && nums[l] > nums[ma]) {\n            ma = l;\n        }\n        if (r < n && nums[r] > nums[ma]) {\n            ma = 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\n        if (ma === i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        [nums[i], nums[ma]] = [nums[ma], nums[i]];\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\n        siftDown(nums, nums.length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        siftDown(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 {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1;\n        let r = 2 * i + 2;\n        let ma = i;\n        if (l < n && nums[l] > nums[ma]) {\n            ma = l;\n        }\n        if (r < n && nums[r] > nums[ma]) {\n            ma = 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\n        if (ma === i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        [nums[i], nums[ma]] = [nums[ma], nums[i]];\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\n        siftDown(nums, nums.length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        siftDown(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) {\n  while (true) {\n    // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n    int l = 2 * i + 1;\n    int r = 2 * i + 2;\n    int ma = i;\n    if (l < n && nums[l] > nums[ma]) ma = l;\n    if (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\n    if (ma == i) break;\n    // \u4ea4\u6362\u4e24\u8282\u70b9\n    int temp = nums[i];\n    nums[i] = nums[ma];\n    nums[ma] = temp;\n    // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n    i = ma;\n  }\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\n  for (int i = nums.length ~/ 2 - 1; i >= 0; i--) {\n    siftDown(nums, nums.length, i);\n  }\n  // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n  for (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    int tmp = nums[0];\n    nums[0] = nums[i];\n    nums[i] = tmp;\n    // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n    siftDown(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) {\n    loop {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1;\n        let r = 2 * i + 2;\n        let mut ma = i;\n        if l < n && nums[l] > nums[ma] {\n            ma = l;\n        }\n        if r < n && nums[r] > nums[ma] {\n            ma = 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\n        if ma == i {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        let temp = nums[i];\n        nums[i] = nums[ma];\n        nums[ma] = temp;\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for i in (0..=nums.len() / 2 - 1).rev() {\n        sift_down(nums, nums.len(), i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\n        let tmp = nums[0];\n        nums[0] = nums[i];\n        nums[i] = tmp;\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        sift_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) {\n    while (1) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        int temp = nums[i];\n        nums[i] = nums[ma];\n        nums[ma] = temp;\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = n / 2 - 1; i >= 0; --i) {\n        siftDown(nums, n, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        int tmp = nums[0];\n        nums[0] = nums[i];\n        nums[i] = tmp;\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(nums, i, 0);\n    }\n}\n
    heap_sort.zig
    [class]{}-[func]{siftDown}\n\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\u4e3a \\(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\u4e3a \\(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]\n    for i in range(1, len(nums)):\n        base = nums[i]\n        j = 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\n        while j >= 0 and nums[j] > base:\n            nums[j + 1] = nums[j]  # \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j -= 1\n        nums[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\n    for (int i = 1; i < nums.size(); i++) {\n        int 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\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n    for (int i = 1; i < nums.length; i++) {\n        int 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\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n    for (int i = 1; i < nums.Length; i++) {\n        int 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\n        while (j >= 0 && nums[j] > bas) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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]\n    for i := 1; i < len(nums); i++ {\n        base := nums[i]\n        j := i - 1\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        for j >= 0 && nums[j] > base {\n            nums[j+1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--\n        }\n        nums[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\n    for i in stride(from: 1, to: nums.count, by: 1) {\n        let base = nums[i]\n        var j = i - 1\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while j >= 0, nums[j] > base {\n            nums[j + 1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j -= 1\n        }\n        nums[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\n    for (let i = 1; i < nums.length; i++) {\n        let base = nums[i],\n            j = i - 1;\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n    for (let i = 1; i < nums.length; i++) {\n        const base = nums[i];\n        let j = i - 1;\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n  for (int i = 1; i < nums.length; i++) {\n    int 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\n    while (j >= 0 && nums[j] > base) {\n      nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n      j--;\n    }\n    nums[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\n    for i in 1..nums.len() {\n        let (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\n        while j >= 0 && nums[j as usize] > base {\n            nums[(j + 1) as usize] = nums[j as usize]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j -= 1;\n        }\n        nums[(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\n    for (int i = 1; i < size; i++) {\n        int 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\n        while (j >= 0 && nums[j] > base) {\n            // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            nums[j + 1] = nums[j];\n            j--;\n        }\n        // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n        nums[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\n    var i: usize = 1;\n    while (i < nums.len) : (i += 1) {\n        var base = nums[i];\n        var j: usize = i;\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while (j >= 1 and nums[j - 1] > base) : (j -= 1) {\n            nums[j] = nums[j - 1];  // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n        }\n        nums[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\u4e3a \\(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\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\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\u7684\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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    # \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    tmp = [0] * (right - left + 1)\n    # \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    i, j, k = left, mid + 1, 0\n    # \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while i <= mid and j <= right:\n        if nums[i] <= nums[j]:\n            tmp[k] = nums[i]\n            i += 1\n        else:\n            tmp[k] = nums[j]\n            j += 1\n        k += 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\n    while i <= mid:\n        tmp[k] = nums[i]\n        i += 1\n        k += 1\n    while j <= right:\n        tmp[k] = nums[j]\n        j += 1\n        k += 1\n    # \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\n    for k in range(0, len(tmp)):\n        nums[left + k] = tmp[k]\n\ndef merge_sort(nums: list[int], left: int, right: int):\n    \"\"\"\u5f52\u5e76\u6392\u5e8f\"\"\"\n    # \u7ec8\u6b62\u6761\u4ef6\n    if left >= right:\n        return  # \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    # \u5212\u5206\u9636\u6bb5\n    mid = (left + right) // 2  # \u8ba1\u7b97\u4e2d\u70b9\n    merge_sort(nums, left, mid)  # \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    merge_sort(nums, mid + 1, right)  # \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    # \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    vector<int> tmp(right - left + 1);\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j])\n            tmp[k++] = nums[i++];\n        else\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.size(); k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(vector<int> &nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right)\n        return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    int[] tmp = new int[right - left + 1];\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j])\n            tmp[k++] = nums[i++];\n        else\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.length; k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int[] nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right)\n        return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2; // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    int[] tmp = new int[right - left + 1];\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j])\n            tmp[k++] = nums[i++];\n        else\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.Length; ++k) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid MergeSort(int[] nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return;       // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\n    MergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    MergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    Merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    tmp := make([]int, right-left+1)\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    i, j, k := left, mid+1, 0\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    for i <= mid && j <= right {\n        if nums[i] <= nums[j] {\n            tmp[k] = nums[i]\n            i++\n        } else {\n            tmp[k] = nums[j]\n            j++\n        }\n        k++\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\n    for i <= mid {\n        tmp[k] = nums[i]\n        i++\n        k++\n    }\n    for j <= right {\n        tmp[k] = nums[j]\n        j++\n        k++\n    }\n    // \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\n    for k := 0; k < len(tmp); k++ {\n        nums[left+k] = tmp[k]\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums []int, left, right int) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if left >= right {\n        return\n    }\n    // \u5212\u5206\u9636\u6bb5\n    mid := (left + right) / 2\n    mergeSort(nums, left, mid)\n    mergeSort(nums, mid+1, right)\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    var 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\n    var i = left, j = mid + 1, k = 0\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while i <= mid, j <= right {\n        if nums[i] <= nums[j] {\n            tmp[k] = nums[i]\n            i += 1\n            k += 1\n        } else {\n            tmp[k] = nums[j]\n            j += 1\n            k += 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\n    while i <= mid {\n        tmp[k] = nums[i]\n        i += 1\n        k += 1\n    }\n    while j <= right {\n        tmp[k] = nums[j]\n        j += 1\n        k += 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\n    for k in tmp.indices {\n        nums[left + k] = tmp[k]\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums: inout [Int], left: Int, right: Int) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if left >= right { // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n        return\n    }\n    // \u5212\u5206\u9636\u6bb5\n    let mid = (left + right) / 2 // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums: &nums, left: left, right: mid) // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums: &nums, left: mid + 1, right: right) // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    const tmp = new Array(right - left + 1);\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    let i = left,\n        j = mid + 1,\n        k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j]) {\n            tmp[k++] = nums[i++];\n        } else {\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.length; k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums, left, right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    let mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    const tmp = new Array(right - left + 1);\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    let i = left,\n        j = mid + 1,\n        k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j]) {\n            tmp[k++] = nums[i++];\n        } else {\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.length; k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums: number[], left: number, right: number): void {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    let mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n  // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n  List<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\n  int i = left, j = mid + 1, k = 0;\n  // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n  while (i <= mid && j <= right) {\n    if (nums[i] <= nums[j])\n      tmp[k++] = nums[i++];\n    else\n      tmp[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\n  while (i <= mid) {\n    tmp[k++] = nums[i++];\n  }\n  while (j <= right) {\n    tmp[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\n  for (k = 0; k < tmp.length; k++) {\n    nums[left + k] = tmp[k];\n  }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(List<int> nums, int left, int right) {\n  // \u7ec8\u6b62\u6761\u4ef6\n  if (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n  // \u5212\u5206\u9636\u6bb5\n  int mid = (left + right) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\n  mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n  mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n  // \u5408\u5e76\u9636\u6bb5\n  merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    let tmp_size = right - left + 1;\n    let mut tmp = vec![0; tmp_size];\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    let (mut i, mut j, mut k) = (left, mid + 1, 0);\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while i <= mid && j <= right {\n        if nums[i] <= nums[j] {\n            tmp[k] = nums[j];\n            i += 1;\n        } else {\n            tmp[k] = nums[j];\n            j += 1;\n        }\n        k += 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\n    while i <= mid {\n        tmp[k] = nums[i];\n        k += 1;\n        i += 1;\n    }\n    while j <= right {\n        tmp[k] = nums[j];\n        k += 1;\n        j += 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\n    for k in 0..tmp_size {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfn merge_sort(nums: &mut [i32], left: usize, right: usize) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if left >= right { return; }             // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    let mid = (left + right) / 2;     // \u8ba1\u7b97\u4e2d\u70b9\n    merge_sort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    merge_sort(nums, mid + 1, right);  // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    int tmpSize = right - left + 1;\n    int *tmp = (int *)malloc(tmpSize * sizeof(int));\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j]) {\n            tmp[k++] = nums[i++];\n        } else {\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmpSize; ++k) {\n        nums[left + k] = tmp[k];\n    }\n    // \u91ca\u653e\u5185\u5b58\n    free(tmp);\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int *nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right)\n        return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\n    var mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n    defer mem_arena.deinit();\n    const mem_allocator = mem_arena.allocator();\n    var tmp = try mem_allocator.alloc(i32, right + 1 - left);\n    std.mem.copy(i32, tmp, nums[left..right+1]);\n    // \u5de6\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15  \n    var leftStart = left - left;\n    var leftEnd = mid - left;\n    // \u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15       \n    var rightStart = mid + 1 - left;\n    var rightEnd = right - left;\n    // i, j \u5206\u522b\u6307\u5411\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\u7684\u9996\u5143\u7d20\n    var i = leftStart;\n    var j = rightStart;\n    // \u901a\u8fc7\u8986\u76d6\u539f\u6570\u7ec4 nums \u6765\u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\n    var k = left;\n    while (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++\n        if (i > leftEnd) {\n            nums[k] = tmp[j];\n            j += 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]) {\n            nums[k] = tmp[i];\n            i += 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 {\n            nums[k] = tmp[j];\n            j += 1;\n        }\n    }\n}\n\n// \u5f52\u5e76\u6392\u5e8f\nfn mergeSort(nums: []i32, left: usize, right: usize) !void {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return;              // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    var mid = (left + right) / 2;           // \u8ba1\u7b97\u4e2d\u70b9\n    try mergeSort(nums, left, mid);         // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    try mergeSort(nums, mid + 1, right);    // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    try 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\u4e3a \\(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\u4e3a \\(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\n    i, j = left, right\n    while i < j:\n        while i < j and nums[j] >= nums[left]:\n            j -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while i < j and nums[i] <= nums[left]:\n            i += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        # \u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    # \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return 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) {\n    int tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nint partition(vector<int> &nums, int left, int right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return 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) {\n    int tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nint partition(int[] nums, int left, int right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return 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\n/* \u54e8\u5175\u5212\u5206 */\nint Partition(int[] nums, int left, int right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return 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\n    i, j := left, right\n    for i < j {\n        for i < j && nums[j] >= nums[left] {\n            j-- // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        for i < j && nums[i] <= nums[left] {\n            i++ // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        // \u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    }\n    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return 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) {\n    let tmp = nums[i]\n    nums[i] = nums[j]\n    nums[j] = tmp\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nfunc partition(nums: inout [Int], left: Int, right: Int) -> Int {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    var i = left\n    var j = right\n    while i < j {\n        while i < j, nums[j] >= nums[left] {\n            j -= 1 // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while i < j, nums[i] <= nums[left] {\n            i += 1 // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        swap(nums: &nums, i: i, j: j) // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    swap(nums: &nums, i: i, j: left) // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return i // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.js
    /* \u5143\u7d20\u4ea4\u6362 */\nswap(nums, i, j) {\n    let tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums, left, right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        // \u5143\u7d20\u4ea4\u6362\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return 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 {\n    let tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums: number[], left: number, right: number): number {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        // \u5143\u7d20\u4ea4\u6362\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return 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) {\n  int tmp = nums[i];\n  nums[i] = nums[j];\n  nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nint _partition(List<int> nums, int left, int right) {\n  // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n  int i = left, j = right;\n  while (i < j) {\n    while (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n    while (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\n  return 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\n    let (mut i, mut j) = (left, right);\n    while i < j {\n        while i < j && nums[j] >= nums[left] {\n            j -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while i < j && nums[i] <= nums[left] {\n            i += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        nums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    nums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    i                    // \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) {\n    int tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            j--;\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            i++;\n        }\n        // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n        swap(nums, i, j);\n    }\n    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    swap(nums, i, left);\n    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n    return i;\n}\n
    quick_sort.zig
    // \u5143\u7d20\u4ea4\u6362\nfn swap(nums: []i32, i: usize, j: usize) void {\n    var tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n// \u54e8\u5175\u5212\u5206\nfn partition(nums: []i32, left: usize, right: usize) usize {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    var i = left;\n    var j = right;\n    while (i < j) {\n        while (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j and nums[i] <= nums[left]) i += 1; // \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\n    return 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\n    if left >= right:\n        return\n    # \u54e8\u5175\u5212\u5206\n    pivot = self.partition(nums, left, right)\n    # \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    self.quick_sort(nums, left, pivot - 1)\n    self.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\n    if (left >= right)\n        return;\n    // \u54e8\u5175\u5212\u5206\n    int pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\n    if (left >= right)\n        return;\n    // \u54e8\u5175\u5212\u5206\n    int pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\n    if (left >= right)\n        return;\n    // \u54e8\u5175\u5212\u5206\n    int pivot = Partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    QuickSort(nums, left, pivot - 1);\n    QuickSort(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\n    if left >= right {\n        return\n    }\n    // \u54e8\u5175\u5212\u5206\n    pivot := q.partition(nums, left, right)\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    q.quickSort(nums, left, pivot-1)\n    q.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\n    if left >= right {\n        return\n    }\n    // \u54e8\u5175\u5212\u5206\n    let pivot = partition(nums: &nums, left: left, right: right)\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums: &nums, left: left, right: pivot - 1)\n    quickSort(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\n    if (left >= right) return;\n    // \u54e8\u5175\u5212\u5206\n    const pivot = this.partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    this.quickSort(nums, left, pivot - 1);\n    this.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\n    if (left >= right) {\n        return;\n    }\n    // \u54e8\u5175\u5212\u5206\n    const pivot = this.partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    this.quickSort(nums, left, pivot - 1);\n    this.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\n  if (left >= right) return;\n  // \u54e8\u5175\u5212\u5206\n  int pivot = _partition(nums, left, right);\n  // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n  quickSort(nums, left, pivot - 1);\n  quickSort(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\n    if left >= right {\n        return;\n    }\n    // \u54e8\u5175\u5212\u5206\n    let pivot = Self::partition(nums, left as usize, right as usize) as i32;\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    Self::quick_sort(left, pivot - 1, nums);\n    Self::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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            j--;\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            i++;\n        }\n        // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n        swap(nums, i, j);\n    }\n    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    swap(nums, i, left);\n    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n    return i;\n}\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\n    if (left >= right) {\n        return;\n    }\n    // \u54e8\u5175\u5212\u5206\n    int pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\n    if (left >= right) return;\n    // \u54e8\u5175\u5212\u5206\n    var pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\u4e3a \\(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\u4e3a \\(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\u5019\u9009\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\n    if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]):\n        return left\n    elif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]):\n        return mid\n    return right\n\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\n    med = self.median_three(nums, left, (left + right) // 2, right)\n    # \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    nums[left], nums[med] = nums[med], nums[left]\n    # \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    i, j = left, right\n    while i < j:\n        while i < j and nums[j] >= nums[left]:\n            j -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while i < j and nums[i] <= nums[left]:\n            i += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        # \u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    # \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return i  # \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n
    quick_sort.cpp
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\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\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.java
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\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\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.cs
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\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\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.go
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\n        return left\n    } else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\n        return mid\n    }\n    return right\n}\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\n    med := q.medianThree(nums, left, (left+right)/2, right)\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    nums[left], nums[med] = nums[med], nums[left]\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    i, j := left, right\n    for i < j {\n        for i < j && nums[j] >= nums[left] {\n            j-- //\u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        for i < j && nums[i] <= nums[left] {\n            i++ //\u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        //\u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    }\n    //\u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return i //\u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.swift
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfunc medianThree(nums: [Int], left: Int, mid: Int, right: Int) -> Int {\n    if (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\n        return left\n    } else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\n        return mid\n    } else {\n        return right\n    }\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\n    let 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\n    swap(nums: &nums, i: left, j: med)\n    return partition(nums: &nums, left: left, right: right)\n}\n
    quick_sort.js
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else return right;\n}\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\n    let med = this.medianThree(\n        nums,\n        left,\n        Math.floor((left + right) / 2),\n        right\n    );\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    this.swap(nums, left, med);\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.ts
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nmedianThree(\n    nums: number[],\n    left: number,\n    mid: number,\n    right: 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\n    if (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) {\n        return left;\n    } else if (\n        Number(nums[mid] < nums[left]) ^ Number(nums[mid] < nums[right])\n    ) {\n        return mid;\n    } else {\n        return right;\n    }\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\n    let med = this.medianThree(\n        nums,\n        left,\n        Math.floor((left + right) / 2),\n        right\n    );\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    this.swap(nums, left, med);\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.dart
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n  if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n    return left;\n  else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n    return mid;\n  else\n    return right;\n}\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\n  int 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\n  int i = left, j = right;\n  while (i < j) {\n    while (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n    while (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\n  return i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.rs
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) {\n        return left;\n    } else if (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]) {\n        return mid;\n    } \n    right\n}\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\n    let med = Self::median_three(nums, left, (left + right) / 2, right);\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    nums.swap(left, med);\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let (mut i, mut j) = (left, right);\n    while i < j {\n        while i < j && nums[j] >= nums[left] {\n            j -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while i < j && nums[i] <= nums[left] {\n            i += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        nums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n     nums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n     i                    // \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\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\n\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */ \nint partitionMedian(int nums[], int left, int right) {\n    // \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.zig
    // \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) != (nums[left] < nums[right])) {\n        return left;\n    } else if ((nums[mid] < nums[left]) != (nums[mid] < nums[right])) {\n        return mid;\n    } else {\n        return right;\n    }\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\n    var 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\n    var i = left;\n    var j = right;\n    while (i < j) {\n        while (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j and nums[i] <= nums[left]) i += 1; // \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\n    return 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\u6709\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\n    while left < right:\n        # \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        pivot = self.partition(nums, left, right)\n        # \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if pivot - left < right - pivot:\n            self.quick_sort(nums, left, pivot - 1)  # \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1  # \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        else:\n            self.quick_sort(nums, pivot + 1, right)  # \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = Partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            QuickSort(nums, left, pivot - 1);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            QuickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    for left < right {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        pivot := q.partition(nums, left, right)\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if pivot-left < right-pivot {\n            q.quickSort(nums, left, pivot-1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            q.quickSort(nums, pivot+1, right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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) {\n    var left = left\n    var right = right\n    // \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\n    while left < right {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if (pivot - left) < (right - pivot) {\n            quickSortTailCall(nums: &nums, left: left, right: pivot - 1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSortTailCall(nums: &nums, left: pivot + 1, right: right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if (pivot - left < right - pivot) {\n            this.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            this.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if (pivot - left < right - pivot) {\n            this.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            this.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n  while (left < right) {\n    // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n    int pivot = _partition(nums, left, right);\n    // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n    if (pivot - left < right - pivot) {\n      quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n      left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n    } else {\n      quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n      right = 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\n    while left < right {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if  pivot - left < right - pivot {\n            Self::quick_sort(left, pivot - 1, nums);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            Self::quick_sort(pivot + 1, right, nums); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSortTailCall(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;                         // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSortTailCall(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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 {\n    var left = left_;\n    var right = right_;\n    // \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        var pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSort(nums, left, pivot - 1);   // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;                   // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSort(nums, pivot + 1, right);  // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\u6a21\uff08\u53d6\u4f59\uff09\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\n    return (num // exp) % 10\n\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\n    counter = [0] * 10\n    n = len(nums)\n    # \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i in range(n):\n        d = digit(nums[i], exp)  # \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i in range(1, 10):\n        counter[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\n    res = [0] * n\n    for i in range(n - 1, -1, -1):\n        d = digit(nums[i], exp)\n        j = counter[d] - 1  # \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]  # \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1  # \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    # \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i in range(n):\n        nums[i] = res[i]\n\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\n    m = max(nums)\n    # \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    exp = 1\n    while 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)\n        counting_sort_digit(nums, exp)\n        exp *= 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\n    return (num / exp) % 10;\n}\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\n    vector<int> counter(10, 0);\n    int n = nums.size();\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < n; i++) {\n        int d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    vector<int> res(n, 0);\n    for (int i = n - 1; i >= 0; i--) {\n        int d = digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < n; i++)\n        nums[i] = res[i];\n}\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\n    int m = *max_element(nums.begin(), nums.end());\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return (num / exp) % 10;\n}\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\n    int[] counter = new int[10];\n    int n = nums.length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < n; i++) {\n        int d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int d = digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < n; i++)\n        nums[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\n    int m = Integer.MIN_VALUE;\n    for (int num : nums)\n        if (num > m)\n            m = num;\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return (num / exp) % 10;\n}\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\n    int[] counter = new int[10];\n    int n = nums.Length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < n; i++) {\n        int d = Digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int d = Digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < n; i++) {\n        nums[i] = res[i];\n    }\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\n    int m = int.MinValue;\n    foreach (int num in nums) {\n        if (num > m) m = num;\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        CountingSortDigit(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\n    return (num / exp) % 10\n}\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\n    counter := make([]int, 10)\n    n := len(nums)\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i := 0; i < n; i++ {\n        d := digit(nums[i], exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i := 1; i < 10; i++ {\n        counter[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\n    res := make([]int, n)\n    for i := n - 1; i >= 0; i-- {\n        d := digit(nums[i], exp)\n        j := counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]    // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i := 0; i < n; i++ {\n        nums[i] = res[i]\n    }\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\n    max := math.MinInt\n    for _, num := range nums {\n        if num > max {\n            max = num\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for 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)\n        countingSortDigit(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\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\n    var counter = Array(repeating: 0, count: 10)\n    let n = nums.count\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i in nums.indices {\n        let d = digit(num: nums[i], exp: exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i in 1 ..< 10 {\n        counter[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\n    var res = Array(repeating: 0, count: n)\n    for i in stride(from: n - 1, through: 0, by: -1) {\n        let d = digit(num: nums[i], exp: exp)\n        let j = counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i] // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1 // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i in nums.indices {\n        nums[i] = res[i]\n    }\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\n    var m = Int.min\n    for num in nums {\n        if num > m {\n            m = num\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for 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)\n        countingSortDigit(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\n    return Math.floor(num / exp) % 10;\n}\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\n    const counter = new Array(10).fill(0);\n    const n = nums.length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (let i = 0; i < n; i++) {\n        const d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (let i = 1; i < 10; i++) {\n        counter[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\n    const res = new Array(n).fill(0);\n    for (let i = n - 1; i >= 0; i--) {\n        const d = digit(nums[i], exp);\n        const j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (let i = 0; i < n; i++) {\n        nums[i] = res[i];\n    }\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\n    let m = Number.MIN_VALUE;\n    for (const num of nums) {\n        if (num > m) {\n            m = num;\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return Math.floor(num / exp) % 10;\n}\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\n    const counter = new Array(10).fill(0);\n    const n = nums.length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (let i = 0; i < n; i++) {\n        const d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (let i = 1; i < 10; i++) {\n        counter[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\n    const res = new Array(n).fill(0);\n    for (let i = n - 1; i >= 0; i--) {\n        const d = digit(nums[i], exp);\n        const j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (let i = 0; i < n; i++) {\n        nums[i] = res[i];\n    }\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\n    let m = Number.MIN_VALUE;\n    for (const num of nums) {\n        if (num > m) {\n            m = num;\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n  return (_num ~/ exp) % 10;\n}\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\n  List<int> counter = List<int>.filled(10, 0);\n  int n = nums.length;\n  // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n  for (int i = 0; i < n; i++) {\n    int d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n    counter[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\n  for (int i = 1; i < 10; i++) {\n    counter[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\n  List<int> res = List<int>.filled(n, 0);\n  for (int i = n - 1; i >= 0; i--) {\n    int d = digit(nums[i], exp);\n    int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n    res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n    counter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n  }\n  // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n  for (int i = 0; i < n; i++) nums[i] = res[i];\n}\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\n  int m = -1 << 63;\n  for (int _num in nums) if (_num > m) m = _num;\n  // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n  for (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)\n    countingSortDigit(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\n    return ((num / exp) % 10) as usize;\n}\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\n    let mut counter = [0; 10];\n    let n = nums.len();\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i in 0..n {\n        let d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i in 1..10 {\n        counter[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\n    let mut res = vec![0; n];\n    for i in (0..n).rev() {\n        let d = digit(nums[i], exp);\n        let j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i in 0..n {\n        nums[i] = res[i];\n    }\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\n    let m = *nums.into_iter().max().unwrap();\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    let mut exp = 1;\n    while exp <= m {\n        counting_sort_digit(nums, exp);\n        exp *= 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\n    return (num / exp) % 10;\n}\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\n    int *counter = (int *)malloc((sizeof(int) * 10));\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < size; i++) {\n        // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        int d = digit(nums[i], exp);\n        // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n        counter[d]++;\n    }\n    // \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    int *res = (int *)malloc(sizeof(int) * size);\n    for (int i = size - 1; i >= 0; i--) {\n        int d = digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < size; i++) {\n        nums[i] = res[i];\n    }\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\n    int max = INT32_MIN;\n    for (size_t i = 0; i < size - 1; i++) {\n        if (nums[i] > max) {\n            max = nums[i];\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return @mod(@divFloor(num, exp), 10);\n}\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\n    var mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n    // defer mem_arena.deinit();\n    const mem_allocator = mem_arena.allocator();\n    var counter = try mem_allocator.alloc(usize, 10);\n    @memset(counter, 0);\n    var n = nums.len;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (nums) |num| {\n        var d: u32 = @bitCast(digit(num, exp)); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    var i: usize = 1;\n    while (i < 10) : (i += 1) {\n        counter[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\n    var res = try mem_allocator.alloc(i32, n);\n    i = n - 1;\n    while (i >= 0) : (i -= 1) {\n        var d: u32 = @bitCast(digit(nums[i], exp));\n        var j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1;        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n        if (i == 0) break;\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    i = 0;\n    while (i < n) : (i += 1) {\n        nums[i] = res[i];\n    }\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\n    var m: i32 = std.math.minInt(i32);\n    for (nums) |num| {\n        if (num > m) m = num;\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    var exp: i32 = 1;\n    while (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)\n        try countingSortDigit(nums, exp);    \n    }\n} \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\u4e3a \\(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\u4e3a \\(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\u5f53\u8ba1\u6570\u6392\u5e8f\u7a33\u5b9a\u65f6\uff0c\u57fa\u6570\u6392\u5e8f\u4e5f\u7a33\u5b9a\uff1b\u5f53\u8ba1\u6570\u6392\u5e8f\u4e0d\u7a33\u5b9a\u65f6\uff0c\u57fa\u6570\u6392\u5e8f\u65e0\u6cd5\u4fdd\u8bc1\u5f97\u5230\u6b63\u786e\u7684\u6392\u5e8f\u7ed3\u679c\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\"\"\"\n    n = len(nums)\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for i in range(n - 1):\n        # \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        k = i\n        for j in range(i + 1, n):\n            if nums[j] < nums[k]:\n                k = 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\n        nums[i], nums[k] = nums[k], nums[i]\n
    selection_sort.cpp
    /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(vector<int> &nums) {\n    int n = nums.size();\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        swap(nums[i], nums[k]);\n    }\n}\n
    selection_sort.java
    /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(int[] nums) {\n    int n = nums.length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        int temp = nums[i];\n        nums[i] = nums[k];\n        nums[k] = temp;\n    }\n}\n
    selection_sort.cs
    /* \u9009\u62e9\u6392\u5e8f */\nvoid SelectionSort(int[] nums) {\n    int n = nums.Length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        (nums[k], nums[i]) = (nums[i], nums[k]);\n    }\n}\n
    selection_sort.go
    /* \u9009\u62e9\u6392\u5e8f */\nfunc selectionSort(nums []int) {\n    n := len(nums)\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for i := 0; i < n-1; i++ {\n        // \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        k := i\n        for j := i + 1; j < n; j++ {\n            if nums[j] < nums[k] {\n                // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n                k = j\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}\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]\n    for i in nums.indices.dropLast() {\n        // \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        var k = i\n        for j in nums.indices.dropFirst(i + 1) {\n            if nums[j] < nums[k] {\n                k = 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.swapAt(i, k)\n    }\n}\n
    selection_sort.js
    /* \u9009\u62e9\u6392\u5e8f */\nfunction selectionSort(nums) {\n    let n = nums.length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        let k = i;\n        for (let j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k]) {\n                k = 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 {\n    let n = nums.length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        let k = i;\n        for (let j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k]) {\n                k = 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) {\n  int n = nums.length;\n  // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n  for (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\n    int k = i;\n    for (int j = i + 1; j < n; j++) {\n      if (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\n    int temp = nums[i];\n    nums[i] = nums[k];\n    nums[k] = temp;\n  }\n}\n
    selection_sort.rs
    /* \u9009\u62e9\u6392\u5e8f */\nfn selection_sort(nums: &mut [i32]) {\n    let n = nums.len();\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for i in 0..n-1 {\n        // \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        let mut k = i;\n        for j in i+1..n {\n            if nums[j] < nums[k] {\n                k = 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.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]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        int temp = nums[i];\n        nums[i] = nums[k];\n        nums[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\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
    • \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\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\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\u5927\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\n# \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217\ndeque: deque[int] = deque()\n\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\n# \u8bbf\u95ee\u5143\u7d20\nfront: int = deque[0]  # \u961f\u9996\u5143\u7d20\nrear: int = deque[-1]  # \u961f\u5c3e\u5143\u7d20\n\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\n# \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(deque)\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint front = deque.front(); // \u961f\u9996\u5143\u7d20\nint back = deque.back();   // \u961f\u5c3e\u5143\u7d20\n\n/* \u5143\u7d20\u51fa\u961f */\ndeque.pop_front();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.pop_back();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.peekFirst();  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.peekLast();    // \u961f\u5c3e\u5143\u7d20\n\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.First.Value;  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.Last.Value;    // \u961f\u5c3e\u5143\u7d20\n\n/* \u5143\u7d20\u51fa\u961f */\ndeque.RemoveFirst();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.RemoveLast();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.Count;\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nfront := deque.Front() // \u961f\u9996\u5143\u7d20\nrear := deque.Back()   // \u961f\u5c3e\u5143\u7d20\n\n/* \u5143\u7d20\u51fa\u961f */\ndeque.Remove(front)    // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.Remove(rear)     // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize := deque.Len()\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nlet peekFirst = deque.first! // \u961f\u9996\u5143\u7d20\nlet peekLast = deque.last! // \u961f\u5c3e\u5143\u7d20\n\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.count\n\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\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\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\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\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\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\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\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\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\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\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.first; // \u961f\u9996\u5143\u7d20\nint peekLast = deque.last;   // \u961f\u5c3e\u5143\u7d20\n\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.length;\n\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\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\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\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n\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\"\"\"\n\n    def __init__(self, val: int):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self.val: int = val\n        self.next: ListNode | None = None  # \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n        self.prev: ListNode | None = None  # \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\nclass LinkedListDeque:\n    \"\"\"\u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._front: ListNode | None = None  # \u5934\u8282\u70b9 front\n        self._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\n        self._size: int = 0  # \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self.size() == 0\n\n    def push(self, num: int, is_front: bool):\n        \"\"\"\u5165\u961f\u64cd\u4f5c\"\"\"\n        node = ListNode(num)\n        # \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if self.is_empty():\n            self._front = self._rear = node\n        # \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        elif is_front:\n            # \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            self._front.prev = node\n            node.next = self._front\n            self._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\n            self._rear.next = node\n            node.prev = self._rear\n            self._rear = node  # \u66f4\u65b0\u5c3e\u8282\u70b9\n        self._size += 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n\n    def push_first(self, num: int):\n        \"\"\"\u961f\u9996\u5165\u961f\"\"\"\n        self.push(num, True)\n\n    def push_last(self, num: int):\n        \"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\n        self.push(num, False)\n\n    def pop(self, is_front: bool) -> int:\n        \"\"\"\u51fa\u961f\u64cd\u4f5c\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        # \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if is_front:\n            val: int = self._front.val  # \u6682\u5b58\u5934\u8282\u70b9\u503c\n            # \u5220\u9664\u5934\u8282\u70b9\n            fnext: ListNode | None = self._front.next\n            if fnext != None:\n                fnext.prev = None\n                self._front.next = None\n            self._front = fnext  # \u66f4\u65b0\u5934\u8282\u70b9\n        # \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else:\n            val: int = self._rear.val  # \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            # \u5220\u9664\u5c3e\u8282\u70b9\n            rprev: ListNode | None = self._rear.prev\n            if rprev != None:\n                rprev.next = None\n                self._rear.prev = None\n            self._rear = rprev  # \u66f4\u65b0\u5c3e\u8282\u70b9\n        self._size -= 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val\n\n    def pop_first(self) -> int:\n        \"\"\"\u961f\u9996\u51fa\u961f\"\"\"\n        return self.pop(True)\n\n    def pop_last(self) -> int:\n        \"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\n        return self.pop(False)\n\n    def peek_first(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        return self._front.val\n\n    def peek_last(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        return self._rear.val\n\n    def to_array(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\"\"\"\n        node = self._front\n        res = [0] * self.size()\n        for i in range(self.size()):\n            res[i] = node.val\n            node = node.next\n        return res\n
    linkedlist_deque.cpp
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nstruct DoublyListNode {\n    int val;              // \u8282\u70b9\u503c\n    DoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\u6307\u9488\n    DoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\u6307\u9488\n    DoublyListNode(int val) : val(val), prev(nullptr), next(nullptr) {\n    }\n};\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n  private:\n    DoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    int queSize = 0;              // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    LinkedListDeque() : front(nullptr), rear(nullptr) {\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~LinkedListDeque() {\n        // \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n        DoublyListNode *pre, *cur = front;\n        while (cur != nullptr) {\n            pre = cur;\n            cur = cur->next;\n            delete pre;\n        }\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    void push(int num, bool isFront) {\n        DoublyListNode *node = new DoublyListNode(num);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (isEmpty())\n            front = rear = node;\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if (isFront) {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front->prev = node;\n            node->next = front;\n            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\n            rear->next = node;\n            node->prev = rear;\n            rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    void pushFirst(int num) {\n        push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    void pushLast(int num) {\n        push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    int pop(bool isFront) {\n        if (isEmpty())\n            throw out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\n        int val;\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if (isFront) {\n            val = front->val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            DoublyListNode *fNext = front->next;\n            if (fNext != nullptr) {\n                fNext->prev = nullptr;\n                front->next = nullptr;\n                delete front;\n            }\n            front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        } else {\n            val = rear->val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            DoublyListNode *rPrev = rear->prev;\n            if (rPrev != nullptr) {\n                rPrev->next = nullptr;\n                rear->prev = nullptr;\n                delete rear;\n            }\n            rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    int popFirst() {\n        return pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    int popLast() {\n        return pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peekFirst() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        return front->val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    int peekLast() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        return rear->val;\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    vector<int> toVector() {\n        DoublyListNode *node = front;\n        vector<int> res(size());\n        for (int i = 0; i < res.size(); i++) {\n            res[i] = node->val;\n            node = node->next;\n        }\n        return res;\n    }\n};\n
    linkedlist_deque.java
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    int val; // \u8282\u70b9\u503c\n    ListNode next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n    ListNode prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\n    ListNode(int val) {\n        this.val = val;\n        prev = next = null;\n    }\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    private ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    private int queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    public LinkedListDeque() {\n        front = rear = null;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    private void push(int num, boolean isFront) {\n        ListNode node = new ListNode(num);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (isEmpty())\n            front = rear = node;\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if (isFront) {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front.prev = node;\n            node.next = front;\n            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\n            rear.next = node;\n            node.prev = rear;\n            rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void pushFirst(int num) {\n        push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    public void pushLast(int num) {\n        push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    private int pop(boolean isFront) {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        int val;\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if (isFront) {\n            val = front.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            ListNode fNext = front.next;\n            if (fNext != null) {\n                fNext.prev = null;\n                front.next = null;\n            }\n            front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        } else {\n            val = rear.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            ListNode rPrev = rear.prev;\n            if (rPrev != null) {\n                rPrev.next = null;\n                rear.prev = null;\n            }\n            rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int popFirst() {\n        return pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int popLast() {\n        return pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peekFirst() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return front.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int peekLast() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return rear.val;\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int[] toArray() {\n        ListNode node = front;\n        int[] res = new int[size()];\n        for (int i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_deque.cs
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode(int val) {\n    public int val = val;       // \u8282\u70b9\u503c\n    public ListNode? next = null; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n    public ListNode? prev = null; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    ListNode? front, rear; // \u5934\u8282\u70b9 front, \u5c3e\u8282\u70b9 rear\n    int queSize = 0;      // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    public LinkedListDeque() {\n        front = null;\n        rear = null;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    void Push(int num, bool isFront) {\n        ListNode node = new(num);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (IsEmpty()) {\n            front = node;\n            rear = node;\n        }\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if (isFront) {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front!.prev = node;\n            node.next = front;\n            front = node; // \u66f4\u65b0\u5934\u8282\u70b9                           \n        }\n        // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n        else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            rear!.next = node;\n            node.prev = rear;\n            rear = node;  // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n\n        queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void PushFirst(int num) {\n        Push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    public void PushLast(int num) {\n        Push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    int? Pop(bool isFront) {\n        if (IsEmpty())\n            throw new Exception();\n        int? val;\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if (isFront) {\n            val = front?.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            ListNode? fNext = front?.next;\n            if (fNext != null) {\n                fNext.prev = null;\n                front!.next = null;\n            }\n            front = fNext;   // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else {\n            val = rear?.val;  // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            ListNode? rPrev = rear?.prev;\n            if (rPrev != null) {\n                rPrev.next = null;\n                rear!.prev = null;\n            }\n            rear = rPrev;    // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n\n        queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int? PopFirst() {\n        return Pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int? PopLast() {\n        return Pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int? PeekFirst() {\n        if (IsEmpty())\n            throw new Exception();\n        return front?.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int? PeekLast() {\n        if (IsEmpty())\n            throw new Exception();\n        return rear?.val;\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int?[] ToArray() {\n        ListNode? node = front;\n        int?[] res = new int?[Size()];\n        for (int i = 0; i < res.Length; i++) {\n            res[i] = node?.val;\n            node = node?.next;\n        }\n\n        return 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\n    data *list.List\n}\n\n/* \u521d\u59cb\u5316\u53cc\u7aef\u961f\u5217 */\nfunc newLinkedListDeque() *linkedListDeque {\n    return &linkedListDeque{\n        data: list.New(),\n    }\n}\n\n/* \u961f\u9996\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushFirst(value any) {\n    s.data.PushFront(value)\n}\n\n/* \u961f\u5c3e\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushLast(value any) {\n    s.data.PushBack(value)\n}\n\n/* \u961f\u9996\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popFirst() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u961f\u5c3e\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popLast() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListDeque) peekFirst() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (s *linkedListDeque) peekLast() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    return e.Value\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListDeque) size() int {\n    return s.data.Len()\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListDeque) isEmpty() bool {\n    return s.data.Len() == 0\n}\n\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListDeque) toList() *list.List {\n    return s.data\n}\n
    linkedlist_deque.swift
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    var val: Int // \u8282\u70b9\u503c\n    var next: ListNode? // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n    weak var prev: ListNode? // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\n    init(val: Int) {\n        self.val = val\n    }\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    private var front: ListNode? // \u5934\u8282\u70b9 front\n    private var rear: ListNode? // \u5c3e\u8282\u70b9 rear\n    private var queSize: Int // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    init() {\n        queSize = 0\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        queSize\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    private func push(num: Int, isFront: Bool) {\n        let node = ListNode(val: num)\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if isEmpty() {\n            front = node\n            rear = node\n        }\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if isFront {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front?.prev = node\n            node.next = front\n            front = node // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n        else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            rear?.next = node\n            node.prev = rear\n            rear = node // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize += 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    func pushFirst(num: Int) {\n        push(num: num, isFront: true)\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    func pushLast(num: Int) {\n        push(num: num, isFront: false)\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    private func pop(isFront: Bool) -> Int {\n        if isEmpty() {\n            fatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        }\n        let val: Int\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if isFront {\n            val = front!.val // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            let fNext = front?.next\n            if fNext != nil {\n                fNext?.prev = nil\n                front?.next = nil\n            }\n            front = fNext // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else {\n            val = rear!.val // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            let rPrev = rear?.prev\n            if rPrev != nil {\n                rPrev?.next = nil\n                rear?.prev = nil\n            }\n            rear = rPrev // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize -= 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    func popFirst() -> Int {\n        pop(isFront: true)\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    func popLast() -> Int {\n        pop(isFront: false)\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peekFirst() -> Int? {\n        isEmpty() ? nil : front?.val\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    func peekLast() -> Int? {\n        isEmpty() ? nil : rear?.val\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    func toArray() -> [Int] {\n        var node = front\n        var res = Array(repeating: 0, count: size())\n        for i in res.indices {\n            res[i] = node!.val\n            node = node?.next\n        }\n        return res\n    }\n}\n
    linkedlist_deque.js
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    val; // \u8282\u70b9\u503c\n\n    constructor(val) {\n        this.val = val;\n        this.next = null;\n        this.prev = null;\n    }\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\n\n    constructor() {\n        this.#front = null;\n        this.#rear = null;\n        this.#queSize = 0;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\n    pushLast(val) {\n        const node = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.#queSize === 0) {\n            this.#front = node;\n            this.#rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            this.#rear.next = node;\n            node.prev = this.#rear;\n            this.#rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        this.#queSize++;\n    }\n\n    /* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\n    pushFirst(val) {\n        const node = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.#queSize === 0) {\n            this.#front = node;\n            this.#rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            this.#front.prev = node;\n            node.next = this.#front;\n            this.#front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        this.#queSize++;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\n    popLast() {\n        if (this.#queSize === 0) {\n            return null;\n        }\n        const value = this.#rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5c3e\u8282\u70b9\n        let temp = this.#rear.prev;\n        if (temp !== null) {\n            temp.next = null;\n            this.#rear.prev = null;\n        }\n        this.#rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        this.#queSize--;\n        return value;\n    }\n\n    /* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\n    popFirst() {\n        if (this.#queSize === 0) {\n            return null;\n        }\n        const value = this.#front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5934\u8282\u70b9\n        let temp = this.#front.next;\n        if (temp !== null) {\n            temp.prev = null;\n            this.#front.next = null;\n        }\n        this.#front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\n        this.#queSize--;\n        return value;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast() {\n        return this.#queSize === 0 ? null : this.#rear.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst() {\n        return this.#queSize === 0 ? null : this.#front.val;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#queSize === 0;\n    }\n\n    /* \u6253\u5370\u53cc\u5411\u961f\u5217 */\n    print() {\n        const arr = [];\n        let temp = this.#front;\n        while (temp !== null) {\n            arr.push(temp.val);\n            temp = temp.next;\n        }\n        console.log('[' + arr.join(', ') + ']');\n    }\n}\n
    linkedlist_deque.ts
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    prev: ListNode; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    next: ListNode; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    val: number; // \u8282\u70b9\u503c\n\n    constructor(val: number) {\n        this.val = val;\n        this.next = null;\n        this.prev = null;\n    }\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    private front: ListNode; // \u5934\u8282\u70b9 front\n    private rear: ListNode; // \u5c3e\u8282\u70b9 rear\n    private queSize: number; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    constructor() {\n        this.front = null;\n        this.rear = null;\n        this.queSize = 0;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\n    pushLast(val: number): void {\n        const node: ListNode = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.queSize === 0) {\n            this.front = node;\n            this.rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            this.rear.next = node;\n            node.prev = this.rear;\n            this.rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        this.queSize++;\n    }\n\n    /* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\n    pushFirst(val: number): void {\n        const node: ListNode = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.queSize === 0) {\n            this.front = node;\n            this.rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            this.front.prev = node;\n            node.next = this.front;\n            this.front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        this.queSize++;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\n    popLast(): number {\n        if (this.queSize === 0) {\n            return null;\n        }\n        const value: number = this.rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5c3e\u8282\u70b9\n        let temp: ListNode = this.rear.prev;\n        if (temp !== null) {\n            temp.next = null;\n            this.rear.prev = null;\n        }\n        this.rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        this.queSize--;\n        return value;\n    }\n\n    /* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\n    popFirst(): number {\n        if (this.queSize === 0) {\n            return null;\n        }\n        const value: number = this.front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5934\u8282\u70b9\n        let temp: ListNode = this.front.next;\n        if (temp !== null) {\n            temp.prev = null;\n            this.front.next = null;\n        }\n        this.front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\n        this.queSize--;\n        return value;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast(): number {\n        return this.queSize === 0 ? null : this.rear.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst(): number {\n        return this.queSize === 0 ? null : this.front.val;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.queSize === 0;\n    }\n\n    /* \u6253\u5370\u53cc\u5411\u961f\u5217 */\n    print(): void {\n        const arr: number[] = [];\n        let temp: ListNode = this.front;\n        while (temp !== null) {\n            arr.push(temp.val);\n            temp = temp.next;\n        }\n        console.log('[' + arr.join(', ') + ']');\n    }\n}\n
    linkedlist_deque.dart
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n  int val; // \u8282\u70b9\u503c\n  ListNode? next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n  ListNode? prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\n  ListNode(this.val, {this.next, this.prev});\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u5bf9\u5217 */\nclass LinkedListDeque {\n  late ListNode? _front; // \u5934\u8282\u70b9 _front\n  late ListNode? _rear; // \u5c3e\u8282\u70b9 _rear\n  int _queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n  LinkedListDeque() {\n    this._front = null;\n    this._rear = null;\n  }\n\n  /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u957f\u5ea6 */\n  int size() {\n    return this._queSize;\n  }\n\n  /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return size() == 0;\n  }\n\n  /* \u5165\u961f\u64cd\u4f5c */\n  void push(int _num, bool isFront) {\n    final ListNode node = ListNode(_num);\n    if (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;\n      node.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;\n      node.prev = _rear;\n      _rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n    }\n    _queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n  }\n\n  /* \u961f\u9996\u5165\u961f */\n  void pushFirst(int _num) {\n    push(_num, true);\n  }\n\n  /* \u961f\u5c3e\u5165\u961f */\n  void pushLast(int _num) {\n    push(_num, false);\n  }\n\n  /* \u51fa\u961f\u64cd\u4f5c */\n  int? pop(bool isFront) {\n    // \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de null\n    if (isEmpty()) {\n      return null;\n    }\n    final int val;\n    if (isFront) {\n      // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n      val = _front!.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n      // \u5220\u9664\u5934\u8282\u70b9\n      ListNode? fNext = _front!.next;\n      if (fNext != null) {\n        fNext.prev = null;\n        _front!.next = null;\n      }\n      _front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n    } else {\n      // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n      val = _rear!.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n      // \u5220\u9664\u5c3e\u8282\u70b9\n      ListNode? rPrev = _rear!.prev;\n      if (rPrev != null) {\n        rPrev.next = null;\n        _rear!.prev = null;\n      }\n      _rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n    }\n    _queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    return val;\n  }\n\n  /* \u961f\u9996\u51fa\u961f */\n  int? popFirst() {\n    return pop(true);\n  }\n\n  /* \u961f\u5c3e\u51fa\u961f */\n  int? popLast() {\n    return pop(false);\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int? peekFirst() {\n    return _front?.val;\n  }\n\n  /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n  int? peekLast() {\n    return _rear?.val;\n  }\n\n  /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n  List<int> toArray() {\n    ListNode? node = _front;\n    final List<int> res = [];\n    for (int i = 0; i < _queSize; i++) {\n      res.add(node!.val);\n      node = node.next;\n    }\n    return res;\n  }\n}\n
    linkedlist_deque.rs
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\npub struct ListNode<T> {\n    pub val: T,                                 // \u8282\u70b9\u503c\n    pub next: Option<Rc<RefCell<ListNode<T>>>>, // \u540e\u7ee7\u8282\u70b9\u6307\u9488\n    pub prev: Option<Rc<RefCell<ListNode<T>>>>, // \u524d\u9a71\u8282\u70b9\u6307\u9488\n}\n\nimpl<T> ListNode<T> {\n    pub fn new(val: T) -> Rc<RefCell<ListNode<T>>> {\n        Rc::new(RefCell::new(ListNode {\n            val,\n            next: None,\n            prev: None,\n        }))\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> {\n    front: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\n    rear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \n    que_size: usize,                            // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n}\n\nimpl<T: Copy> LinkedListDeque<T> {\n    pub fn new() -> Self {\n        Self {\n            front: None,\n            rear: None,\n            que_size: 0, \n        }\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        return self.que_size;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        return self.size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    pub fn push(&mut self, num: T, is_front: bool) {\n        let node = ListNode::new(num);\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        if is_front {\n            match self.front.take() {\n                // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n                None => {\n                    self.rear = Some(node.clone());\n                    self.front = Some(node);\n                }\n                // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n                Some(old_front) => {\n                    old_front.borrow_mut().prev = Some(node.clone());\n                    node.borrow_mut().next = Some(old_front);\n                    self.front = Some(node); // \u66f4\u65b0\u5934\u8282\u70b9\n                }\n            }\n        } \n        // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n        else {\n            match self.rear.take() {\n                // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n                None => {\n                    self.front = Some(node.clone());\n                    self.rear = Some(node);\n                }\n                // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n                Some(old_rear) => {\n                    old_rear.borrow_mut().next = Some(node.clone());\n                    node.borrow_mut().prev = Some(old_rear);\n                    self.rear = Some(node); // \u66f4\u65b0\u5c3e\u8282\u70b9\n                }\n            }\n        }\n        self.que_size += 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pub fn push_first(&mut self, num: T) {\n        self.push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pub fn push_last(&mut self, num: T) {\n        self.push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    pub fn pop(&mut self, is_front: bool) -> Option<T> {\n        // \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de None\n        if self.is_empty() { \n            return None \n        };\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if is_front {\n            self.front.take().map(|old_front| {\n                match old_front.borrow_mut().next.take() {\n                    Some(new_front) => {\n                        new_front.borrow_mut().prev.take();\n                        self.front = Some(new_front);   // \u66f4\u65b0\u5934\u8282\u70b9\n                    }\n                    None => {\n                        self.rear.take();\n                    }\n                }\n                self.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n                Rc::try_unwrap(old_front).ok().unwrap().into_inner().val\n            })\n\n        } \n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else {\n            self.rear.take().map(|old_rear| {\n                match old_rear.borrow_mut().prev.take() {\n                    Some(new_rear) => {\n                        new_rear.borrow_mut().next.take();\n                        self.rear = Some(new_rear);     // \u66f4\u65b0\u5c3e\u8282\u70b9\n                    }\n                    None => {\n                        self.front.take();\n                    }\n                }\n                self.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n                Rc::try_unwrap(old_rear).ok().unwrap().into_inner().val\n            })\n        }\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    pub fn pop_first(&mut self) -> Option<T> {\n        return self.pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    pub fn pop_last(&mut self) -> Option<T> {\n        return self.pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    pub fn peek_first(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.front.as_ref()\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    pub fn peek_last(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.rear.as_ref()\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\n        if let Some(node) = head {\n            let mut nums = self.to_array(node.borrow().next.as_ref());\n            nums.insert(0, node.borrow().val);\n            return nums;\n        }\n        return Vec::new();\n    }\n}\n
    linkedlist_deque.c
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\ntypedef struct DoublyListNode {\n    int val;                     // \u8282\u70b9\u503c\n    struct DoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\n    struct DoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\n} DoublyListNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nDoublyListNode *newDoublyListNode(int num) {\n    DoublyListNode *new = (DoublyListNode *)malloc(sizeof(DoublyListNode));\n    new->val = num;\n    new->next = NULL;\n    new->prev = NULL;\n    return new;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delDoublyListNode(DoublyListNode *node) {\n    free(node);\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\n    DoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    int queSize;                  // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n} LinkedListDeque;\n\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListDeque *newLinkedListDeque() {\n    LinkedListDeque *deque = (LinkedListDeque *)malloc(sizeof(LinkedListDeque));\n    deque->front = NULL;\n    deque->rear = NULL;\n    deque->queSize = 0;\n    return deque;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListdeque(LinkedListDeque *deque) {\n    // \u91ca\u653e\u6240\u6709\u8282\u70b9\n    for (int i = 0; i < deque->queSize && deque->front != NULL; i++) {\n        DoublyListNode *tmp = deque->front;\n        deque->front = deque->front->next;\n        free(tmp);\n    }\n    // \u91ca\u653e deque \u7ed3\u6784\u4f53\n    free(deque);\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListDeque *deque) {\n    return deque->queSize;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListDeque *deque) {\n    return (size(deque) == 0);\n}\n\n/* \u5165\u961f */\nvoid push(LinkedListDeque *deque, int num, bool isFront) {\n    DoublyListNode *node = newDoublyListNode(num);\n    // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411node\n    if (empty(deque)) {\n        deque->front = deque->rear = node;\n    }\n    // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n    else if (isFront) {\n        // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n        deque->front->prev = node;\n        node->next = deque->front;\n        deque->front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n    }\n    // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n    else {\n        // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n        deque->rear->next = node;\n        node->prev = deque->rear;\n        deque->rear = node;\n    }\n    deque->queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(LinkedListDeque *deque, int num) {\n    push(deque, num, true);\n}\n\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(LinkedListDeque *deque, int num) {\n    push(deque, num, false);\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(LinkedListDeque *deque) {\n    assert(size(deque) && deque->front);\n    return deque->front->val;\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(LinkedListDeque *deque) {\n    assert(size(deque) && deque->rear);\n    return deque->rear->val;\n}\n\n/* \u51fa\u961f */\nint pop(LinkedListDeque *deque, bool isFront) {\n    if (empty(deque))\n        return -1;\n    int val;\n    // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n    if (isFront) {\n        val = peekFirst(deque); // \u6682\u5b58\u5934\u8282\u70b9\u503c\n        DoublyListNode *fNext = deque->front->next;\n        if (fNext) {\n            fNext->prev = NULL;\n            deque->front->next = NULL;\n            delDoublyListNode(deque->front);\n        }\n        deque->front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n    }\n    // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n    else {\n        val = peekLast(deque); // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n        DoublyListNode *rPrev = deque->rear->prev;\n        if (rPrev) {\n            rPrev->next = NULL;\n            deque->rear->prev = NULL;\n            delDoublyListNode(deque->rear);\n        }\n        deque->rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n    }\n    deque->queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    return val;\n}\n\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(LinkedListDeque *deque) {\n    return pop(deque, true);\n}\n\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(LinkedListDeque *deque) {\n    return pop(deque, false);\n}\n\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListDeque(LinkedListDeque *deque) {\n    int *arr = malloc(sizeof(int) * deque->queSize);\n    // \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\n    int i;\n    DoublyListNode *node;\n    for (i = 0, node = deque->front; i < deque->queSize; i++) {\n        arr[i] = node->val;\n        node = node->next;\n    }\n    printArray(arr, deque->queSize);\n    free(arr);\n}\n
    linkedlist_deque.zig
    // \u53cc\u5411\u94fe\u8868\u8282\u70b9\nfn ListNode(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        val: T = undefined,     // \u8282\u70b9\u503c\n        next: ?*Self = null,    // \u540e\u7ee7\u8282\u70b9\u6307\u9488\n        prev: ?*Self = null,    // \u524d\u9a71\u8282\u70b9\u6307\u9488\n\n        // Initialize a list node with specific value\n        pub fn init(self: *Self, x: i32) void {\n            self.val = x;\n            self.next = null;\n            self.prev = null;\n        }\n    };\n}\n\n// \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\nfn LinkedListDeque(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        front: ?*ListNode(T) = null,                    // \u5934\u8282\u70b9 front\n        rear: ?*ListNode(T) = null,                     // \u5c3e\u8282\u70b9 rear\n        que_size: usize = 0,                             // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.front = null;\n            self.rear = null;\n            self.que_size = 0;\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.que_size;\n        }\n\n        // \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u5165\u961f\u64cd\u4f5c\n        pub fn push(self: *Self, num: T, is_front: bool) !void {\n            var node = try self.mem_allocator.create(ListNode(T));\n            node.init(num);\n            // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n            if (self.isEmpty()) {\n                self.front = node;\n                self.rear = node;\n            // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n            } else if (is_front) {\n                // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n                self.front.?.prev = node;\n                node.next = self.front;\n                self.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\n                self.rear.?.next = node;\n                node.prev = self.rear;\n                self.rear = node;   // \u66f4\u65b0\u5c3e\u8282\u70b9\n            }\n            self.que_size += 1;      // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        } \n\n        // \u961f\u9996\u5165\u961f\n        pub fn pushFirst(self: *Self, num: T) !void {\n            try self.push(num, true);\n        } \n\n        // \u961f\u5c3e\u5165\u961f\n        pub fn pushLast(self: *Self, num: T) !void {\n            try self.push(num, false);\n        } \n\n        // \u51fa\u961f\u64cd\u4f5c\n        pub fn pop(self: *Self, is_front: bool) T {\n            if (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n            var val: T = undefined;\n            // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n            if (is_front) {\n                val = self.front.?.val;     // \u6682\u5b58\u5934\u8282\u70b9\u503c\n                // \u5220\u9664\u5934\u8282\u70b9\n                var fNext = self.front.?.next;\n                if (fNext != null) {\n                    fNext.?.prev = null;\n                    self.front.?.next = null;\n                }\n                self.front = fNext;         // \u66f4\u65b0\u5934\u8282\u70b9\n            // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n            } else {\n                val = self.rear.?.val;      // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n                // \u5220\u9664\u5c3e\u8282\u70b9\n                var rPrev = self.rear.?.prev;\n                if (rPrev != null) {\n                    rPrev.?.next = null;\n                    self.rear.?.prev = null;\n                }\n                self.rear = rPrev;          // \u66f4\u65b0\u5c3e\u8282\u70b9\n            }\n            self.que_size -= 1;              // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n            return val;\n        } \n\n        // \u961f\u9996\u51fa\u961f\n        pub fn popFirst(self: *Self) T {\n            return self.pop(true);\n        } \n\n        // \u961f\u5c3e\u51fa\u961f\n        pub fn popLast(self: *Self) T {\n            return self.pop(false);\n        } \n\n        // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\n        pub fn peekFirst(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n            return self.front.?.val;\n        }  \n\n        // \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\n        pub fn peekLast(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n            return self.rear.?.val;\n        }\n\n        // \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\n        pub fn toArray(self: *Self) ![]T {\n            var node = self.front;\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            while (i < res.len) : (i += 1) {\n                res[i] = node.?.val;\n                node = node.?.next;\n            }\n            return 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\"\"\"\n\n    def __init__(self, capacity: int):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._nums: list[int] = [0] * capacity\n        self._front: int = 0\n        self._size: int = 0\n\n    def capacity(self) -> int:\n        \"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\n        return len(self._nums)\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self._size == 0\n\n    def 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\n        return (i + self.capacity()) % self.capacity()\n\n    def push_first(self, num: int):\n        \"\"\"\u961f\u9996\u5165\u961f\"\"\"\n        if self._size == self.capacity():\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        # \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        # \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        self._front = self.index(self._front - 1)\n        # \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        self._nums[self._front] = num\n        self._size += 1\n\n    def push_last(self, num: int):\n        \"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\n        if self._size == self.capacity():\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        # \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        rear = self.index(self._front + self._size)\n        # \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self._nums[rear] = num\n        self._size += 1\n\n    def pop_first(self) -> int:\n        \"\"\"\u961f\u9996\u51fa\u961f\"\"\"\n        num = self.peek_first()\n        # \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        self._front = self.index(self._front + 1)\n        self._size -= 1\n        return num\n\n    def pop_last(self) -> int:\n        \"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\n        num = self.peek_last()\n        self._size -= 1\n        return num\n\n    def peek_first(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        return self._nums[self._front]\n\n    def peek_last(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        # \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        last = self.index(self._front + self._size - 1)\n        return self._nums[last]\n\n    def 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\n        res = []\n        for i in range(self._size):\n            res.append(self._nums[self.index(self._front + i)])\n        return res\n
    array_deque.cpp
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n  private:\n    vector<int> nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;        // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;      // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    ArrayDeque(int capacity) {\n        nums.resize(capacity);\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    int capacity() {\n        return nums.size();\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    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\n        return (i + capacity()) % capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    void pushFirst(int num) {\n        if (queSize == capacity()) {\n            cout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\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\n    /* \u961f\u5c3e\u5165\u961f */\n    void pushLast(int num) {\n        if (queSize == capacity()) {\n            cout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        int rear = index(front + queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    int popFirst() {\n        int num = peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = index(front + 1);\n        queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    int popLast() {\n        int num = peekLast();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peekFirst() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        return nums[front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    int peekLast() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        int last = index(front + queSize - 1);\n        return nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    vector<int> toVector() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        vector<int> res(queSize);\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[index(j)];\n        }\n        return res;\n    }\n};\n
    array_deque.java
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    private int[] nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private int queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public ArrayDeque(int capacity) {\n        this.nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    public int capacity() {\n        return nums.length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    private 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\n        return (i + capacity()) % capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void pushFirst(int num) {\n        if (queSize == capacity()) {\n            System.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\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\n    /* \u961f\u5c3e\u5165\u961f */\n    public void pushLast(int num) {\n        if (queSize == capacity()) {\n            System.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        int rear = index(front + queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int popFirst() {\n        int num = peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = index(front + 1);\n        queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int popLast() {\n        int num = peekLast();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peekFirst() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return nums[front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int peekLast() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        int last = index(front + queSize - 1);\n        return nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int[] toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.cs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    int[] nums;  // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public ArrayDeque(int capacity) {\n        nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    int Capacity() {\n        return nums.Length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    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\n        return (i + Capacity()) % Capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void PushFirst(int num) {\n        if (queSize == Capacity()) {\n            Console.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\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\n    /* \u961f\u5c3e\u5165\u961f */\n    public void PushLast(int num) {\n        if (queSize == Capacity()) {\n            Console.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        int rear = Index(front + queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int PopFirst() {\n        int num = PeekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = Index(front + 1);\n        queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int PopLast() {\n        int num = PeekLast();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int PeekFirst() {\n        if (IsEmpty()) {\n            throw new InvalidOperationException();\n        }\n        return nums[front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int PeekLast() {\n        if (IsEmpty()) {\n            throw new InvalidOperationException();\n        }\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        int last = Index(front + queSize - 1);\n        return nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int[] ToArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[Index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.go
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntype arrayDeque struct {\n    nums        []int // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    queSize     int   // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n    queCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayDeque(queCapacity int) *arrayDeque {\n    return &arrayDeque{\n        nums:        make([]int, queCapacity),\n        queCapacity: queCapacity,\n        front:       0,\n        queSize:     0,\n    }\n}\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayDeque) size() int {\n    return q.queSize\n}\n\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayDeque) isEmpty() bool {\n    return q.queSize == 0\n}\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\n    return (i + q.queCapacity) % q.queCapacity\n}\n\n/* \u961f\u9996\u5165\u961f */\nfunc (q *arrayDeque) pushFirst(num int) {\n    if q.queSize == q.queCapacity {\n        fmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n        return\n    }\n    // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n    q.front = q.index(q.front - 1)\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n    q.nums[q.front] = num\n    q.queSize++\n}\n\n/* \u961f\u5c3e\u5165\u961f */\nfunc (q *arrayDeque) pushLast(num int) {\n    if q.queSize == q.queCapacity {\n        fmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n        return\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    rear := q.index(q.front + q.queSize)\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n    q.nums[rear] = num\n    q.queSize++\n}\n\n/* \u961f\u9996\u51fa\u961f */\nfunc (q *arrayDeque) popFirst() any {\n    num := q.peekFirst()\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    q.front = q.index(q.front + 1)\n    q.queSize--\n    return num\n}\n\n/* \u961f\u5c3e\u51fa\u961f */\nfunc (q *arrayDeque) popLast() any {\n    num := q.peekLast()\n    q.queSize--\n    return num\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayDeque) peekFirst() any {\n    if q.isEmpty() {\n        return nil\n    }\n    return q.nums[q.front]\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (q *arrayDeque) peekLast() any {\n    if q.isEmpty() {\n        return nil\n    }\n    // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n    last := q.index(q.front + q.queSize - 1)\n    return q.nums[last]\n}\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\n    res := make([]int, q.queSize)\n    for i, j := 0, q.front; i < q.queSize; i++ {\n        res[i] = q.nums[q.index(j)]\n        j++\n    }\n    return res\n}\n
    array_deque.swift
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    private var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private var front: Int // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private var queSize: Int // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init(capacity: Int) {\n        nums = Array(repeating: 0, count: capacity)\n        front = 0\n        queSize = 0\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    func capacity() -> Int {\n        nums.count\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        queSize\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    private 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\n    /* \u961f\u9996\u5165\u961f */\n    func pushFirst(num: Int) {\n        if size() == capacity() {\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        front = index(i: front - 1)\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        nums[front] = num\n        queSize += 1\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    func pushLast(num: Int) {\n        if size() == capacity() {\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        let rear = index(i: front + size())\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num\n        queSize += 1\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    func popFirst() -> Int {\n        let num = peekFirst()\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = index(i: front + 1)\n        queSize -= 1\n        return num\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    func popLast() -> Int {\n        let num = peekLast()\n        queSize -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peekFirst() -> Int {\n        if isEmpty() {\n            fatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        }\n        return nums[front]\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    func peekLast() -> Int {\n        if isEmpty() {\n            fatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        }\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        let last = index(i: front + size() - 1)\n        return nums[last]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    func toArray() -> [Int] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        var res = Array(repeating: 0, count: size())\n        for (i, j) in sequence(first: (0, front), next: { $0 < self.size() - 1 ? ($0 + 1, $1 + 1) : nil }) {\n            res[i] = nums[index(i: j)]\n        }\n        return 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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(capacity) {\n        this.#nums = new Array(capacity);\n        this.#front = 0;\n        this.#queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    capacity() {\n        return this.#nums.length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#queSize === 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    index(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\n        return (i + this.capacity()) % this.capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pushFirst(num) {\n        if (this.#queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        this.#front = this.index(this.#front - 1);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        this.#nums[this.#front] = num;\n        this.#queSize++;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pushLast(num) {\n        if (this.#queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        const rear = this.index(this.#front + this.#queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.#nums[rear] = num;\n        this.#queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    popFirst() {\n        const num = this.peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        this.#front = this.index(this.#front + 1);\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    popLast() {\n        const num = this.peekLast();\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst() {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        return this.#nums[this.#front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast() {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        const last = this.index(this.#front + this.#queSize - 1);\n        return this.#nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const res = [];\n        for (let i = 0, j = this.#front; i < this.#queSize; i++, j++) {\n            res[i] = this.#nums[this.index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.ts
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    private nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private queSize: number; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(capacity: number) {\n        this.nums = new Array(capacity);\n        this.front = 0;\n        this.queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    capacity(): number {\n        return this.nums.length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.queSize === 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    index(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\n        return (i + this.capacity()) % this.capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pushFirst(num: number): void {\n        if (this.queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        this.front = this.index(this.front - 1);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        this.nums[this.front] = num;\n        this.queSize++;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pushLast(num: number): void {\n        if (this.queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        const rear: number = this.index(this.front + this.queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.nums[rear] = num;\n        this.queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    popFirst(): number {\n        const num: number = this.peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        this.front = this.index(this.front + 1);\n        this.queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    popLast(): number {\n        const num: number = this.peekLast();\n        this.queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst(): number {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        return this.nums[this.front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast(): number {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        const last = this.index(this.front + this.queSize - 1);\n        return this.nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    toArray(): number[] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const res: number[] = [];\n        for (let i = 0, j = this.front; i < this.queSize; i++, j++) {\n            res[i] = this.nums[this.index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.dart
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n  late List<int> _nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n  late int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n  late int _queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  ArrayDeque(int capacity) {\n    this._nums = List.filled(capacity, 0);\n    this._front = this._queSize = 0;\n  }\n\n  /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n  int capacity() {\n    return _nums.length;\n  }\n\n  /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n  int size() {\n    return _queSize;\n  }\n\n  /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _queSize == 0;\n  }\n\n  /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n  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\n    return (i + capacity()) % capacity();\n  }\n\n  /* \u961f\u9996\u5165\u961f */\n  void pushFirst(int _num) {\n    if (_queSize == capacity()) {\n      throw 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\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\n  /* \u961f\u5c3e\u5165\u961f */\n  void pushLast(int _num) {\n    if (_queSize == capacity()) {\n      throw Exception(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    int rear = index(_front + _queSize);\n    // \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    _nums[rear] = _num;\n    _queSize++;\n  }\n\n  /* \u961f\u9996\u51fa\u961f */\n  int popFirst() {\n    int _num = peekFirst();\n    // \u961f\u9996\u6307\u9488\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n    _front = index(_front + 1);\n    _queSize--;\n    return _num;\n  }\n\n  /* \u961f\u5c3e\u51fa\u961f */\n  int popLast() {\n    int _num = peekLast();\n    _queSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int peekFirst() {\n    if (isEmpty()) {\n      throw Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n    }\n    return _nums[_front];\n  }\n\n  /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n  int peekLast() {\n    if (isEmpty()) {\n      throw Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n    }\n    // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n    int last = index(_front + _queSize - 1);\n    return _nums[last];\n  }\n\n  /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n  List<int> toArray() {\n    // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n    List<int> res = List.filled(_queSize, 0);\n    for (int i = 0, j = _front; i < _queSize; i++, j++) {\n      res[i] = _nums[index(j)];\n    }\n    return res;\n  }\n}\n
    array_deque.rs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nstruct ArrayDeque {\n    nums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front: usize,       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    que_size: usize,    // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n}\n\nimpl ArrayDeque {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(capacity: usize) -> Self {\n        Self {\n            nums: vec![0; capacity],\n            front: 0,\n            que_size: 0,\n        }\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    pub fn capacity(&self) -> usize {\n        self.nums.len()\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        self.que_size\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        self.que_size == 0\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    fn 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\n        return ((i + self.capacity() as i32) % self.capacity() as i32) as usize;\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pub fn push_first(&mut self, num: i32) {\n        if self.que_size == self.capacity() {\n            println!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        self.front = self.index(self.front as i32 - 1);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        self.nums[self.front] = num;\n        self.que_size += 1;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pub fn push_last(&mut self, num: i32) {\n        if self.que_size == self.capacity() {\n            println!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        let rear = self.index(self.front as i32 + self.que_size as i32);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self.nums[rear] = num;\n        self.que_size += 1;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    fn pop_first(&mut self) -> i32 {\n        let num = self.peek_first();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        self.front = self.index(self.front as i32 + 1);\n        self.que_size -= 1;\n        num\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    fn pop_last(&mut self) -> i32 {\n        let num = self.peek_last();\n        self.que_size -= 1;\n        num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    fn peek_first(&self) -> i32 {\n        if self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\n        self.nums[self.front]\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    fn peek_last(&self) -> i32 {\n        if self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        let last = self.index(self.front as i32 + self.que_size as i32 - 1);\n        self.nums[last]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    fn to_array(&self) -> Vec<i32> {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        let mut res = vec![0; self.que_size];\n        let mut j = self.front;\n        for i in 0..self.que_size {\n            res[i] = self.nums[self.index(j as i32)];\n            j += 1;\n        }\n        res\n    }\n}\n
    array_deque.c
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\n    int *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\n    int queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayDeque;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayDeque *newArrayDeque(int capacity) {\n    ArrayDeque *deque = (ArrayDeque *)malloc(sizeof(ArrayDeque));\n    // \u521d\u59cb\u5316\u6570\u7ec4\n    deque->queCapacity = capacity;\n    deque->nums = (int *)malloc(sizeof(int) * deque->queCapacity);\n    deque->front = deque->queSize = 0;\n    return deque;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayDeque(ArrayDeque *deque) {\n    free(deque->nums);\n    free(deque);\n}\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayDeque *deque) {\n    return deque->queCapacity;\n}\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayDeque *deque) {\n    return deque->queSize;\n}\n\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayDeque *deque) {\n    return deque->queSize == 0;\n}\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\n    return ((i + capacity(deque)) % capacity(deque));\n}\n\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(ArrayDeque *deque, int num) {\n    if (deque->queSize == capacity(deque)) {\n        printf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\n        return;\n    }\n    // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u56de\u5230\u5c3e\u90e8\n    deque->front = dequeIndex(deque, deque->front - 1);\n    // \u5c06 num \u6dfb\u52a0\u5230\u961f\u9996\n    deque->nums[deque->front] = num;\n    deque->queSize++;\n}\n\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(ArrayDeque *deque, int num) {\n    if (deque->queSize == capacity(deque)) {\n        printf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\n        return;\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    int rear = dequeIndex(deque, deque->front + deque->queSize);\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    deque->nums[rear] = num;\n    deque->queSize++;\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(ArrayDeque *deque) {\n    // \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\n    assert(empty(deque) == 0);\n    return deque->nums[deque->front];\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(ArrayDeque *deque) {\n    // \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\n    assert(empty(deque) == 0);\n    int last = dequeIndex(deque, deque->front + deque->queSize - 1);\n    return deque->nums[last];\n}\n\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(ArrayDeque *deque) {\n    int num = peekFirst(deque);\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    deque->front = dequeIndex(deque, deque->front + 1);\n    deque->queSize--;\n    return num;\n}\n\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(ArrayDeque *deque) {\n    int num = peekLast(deque);\n    deque->queSize--;\n    return 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\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\n# \u5143\u7d20\u5165\u961f\nque.append(1)\nque.append(3)\nque.append(2)\nque.append(5)\nque.append(4)\n\n# \u8bbf\u95ee\u961f\u9996\u5143\u7d20\nfront: int = que[0];\n\n# \u5143\u7d20\u51fa\u961f\npop: int = que.popleft()\n\n# \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(que)\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint front = queue.front();\n\n/* \u5143\u7d20\u51fa\u961f */\nqueue.pop();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.offer(1);\nqueue.offer(3);\nqueue.offer(2);\nqueue.offer(5);\nqueue.offer(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.peek();\n\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.poll();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.Enqueue(1);\nqueue.Enqueue(3);\nqueue.Enqueue(2);\nqueue.Enqueue(5);\nqueue.Enqueue(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.Peek();\n\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.Dequeue();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.Count;\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.PushBack(1)\nqueue.PushBack(3)\nqueue.PushBack(2)\nqueue.PushBack(5)\nqueue.PushBack(4)\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek := queue.Front()\n\n/* \u5143\u7d20\u51fa\u961f */\npop := queue.Front()\nqueue.Remove(pop)\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nsize := queue.Len()\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.append(1)\nqueue.append(3)\nqueue.append(2)\nqueue.append(5)\nqueue.append(4)\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nlet peek = queue.first!\n\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\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = queue.count\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n\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\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n\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\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.add(1);\nqueue.add(3);\nqueue.add(2);\nqueue.add(5);\nqueue.add(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.first;\n\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.removeFirst();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.length;\n\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\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\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nif let Some(front) = deque.front() {\n}\n\n/* \u5143\u7d20\u51fa\u961f */\nif let Some(pop) = deque.pop_front() {\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n\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\uff0c\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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._front: ListNode | None = None  # \u5934\u8282\u70b9 front\n        self._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\n        self._size: int = 0\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return not self._front\n\n    def push(self, num: int):\n        \"\"\"\u5165\u961f\"\"\"\n        # \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        node = ListNode(num)\n        # \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n        if self._front is None:\n            self._front = node\n            self._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:\n            self._rear.next = node\n            self._rear = node\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u961f\"\"\"\n        num = self.peek()\n        # \u5220\u9664\u5934\u8282\u70b9\n        self._front = self._front.next\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\n        return self._front.val\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        queue = []\n        temp = self._front\n        while temp:\n            queue.append(temp.val)\n            temp = temp.next\n        return queue\n
    linkedlist_queue.cpp
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n  private:\n    ListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    int queSize;\n\n  public:\n    LinkedListQueue() {\n        front = nullptr;\n        rear = nullptr;\n        queSize = 0;\n    }\n\n    ~LinkedListQueue() {\n        // \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n        freeMemoryLinkedList(front);\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u5165\u961f */\n    void push(int num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        ListNode *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\n        if (front == nullptr) {\n            front = node;\n            rear = node;\n        }\n        // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n        else {\n            rear->next = node;\n            rear = node;\n        }\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    int pop() {\n        int num = peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        ListNode *tmp = front;\n        front = front->next;\n        // \u91ca\u653e\u5185\u5b58\n        delete tmp;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peek() {\n        if (size() == 0)\n            throw out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\n        return front->val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\n    vector<int> toVector() {\n        ListNode *node = front;\n        vector<int> res(size());\n        for (int i = 0; i < res.size(); i++) {\n            res[i] = node->val;\n            node = node->next;\n        }\n        return res;\n    }\n};\n
    linkedlist_queue.java
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    private ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    private int queSize = 0;\n\n    public LinkedListQueue() {\n        front = null;\n        rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f */\n    public void push(int num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        ListNode 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\n        if (front == null) {\n            front = node;\n            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 {\n            rear.next = node;\n            rear = node;\n        }\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int pop() {\n        int num = peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        front = front.next;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return front.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] toArray() {\n        ListNode node = front;\n        int[] res = new int[size()];\n        for (int i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_queue.cs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    ListNode? front, rear;  // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear \n    int queSize = 0;\n\n    public LinkedListQueue() {\n        front = null;\n        rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u961f */\n    public void Push(int num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        ListNode node = new(num);\n        // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n        if (front == null) {\n            front = node;\n            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 if (rear != null) {\n            rear.next = node;\n            rear = node;\n        }\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int Pop() {\n        int num = Peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        front = front?.next;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return front!.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] ToArray() {\n        if (front == null)\n            return [];\n\n        ListNode? node = front;\n        int[] res = new int[Size()];\n        for (int i = 0; i < res.Length; i++) {\n            res[i] = node!.val;\n            node = node.next;\n        }\n        return 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\n    data *list.List\n}\n\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newLinkedListQueue() *linkedListQueue {\n    return &linkedListQueue{\n        data: list.New(),\n    }\n}\n\n/* \u5165\u961f */\nfunc (s *linkedListQueue) push(value any) {\n    s.data.PushBack(value)\n}\n\n/* \u51fa\u961f */\nfunc (s *linkedListQueue) pop() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListQueue) peek() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    return e.Value\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListQueue) size() int {\n    return s.data.Len()\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListQueue) isEmpty() bool {\n    return s.data.Len() == 0\n}\n\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListQueue) toList() *list.List {\n    return s.data\n}\n
    linkedlist_queue.swift
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    private var front: ListNode? // \u5934\u8282\u70b9\n    private var rear: ListNode? // \u5c3e\u8282\u70b9\n    private var _size = 0\n\n    init() {}\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        _size\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u5165\u961f */\n    func push(num: Int) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        let 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\n        if front == nil {\n            front = node\n            rear = node\n        }\n        // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n        else {\n            rear?.next = node\n            rear = node\n        }\n        _size += 1\n    }\n\n    /* \u51fa\u961f */\n    @discardableResult\n    func pop() -> Int {\n        let num = peek()\n        // \u5220\u9664\u5934\u8282\u70b9\n        front = front?.next\n        _size -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n        }\n        return front!.val\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    func toArray() -> [Int] {\n        var node = front\n        var res = Array(repeating: 0, count: size())\n        for i in res.indices {\n            res[i] = node!.val\n            node = node?.next\n        }\n        return 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;\n\n    constructor() {\n        this.#front = null;\n        this.#rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.size === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        const 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\n        if (!this.#front) {\n            this.#front = node;\n            this.#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 {\n            this.#rear.next = node;\n            this.#rear = node;\n        }\n        this.#queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop() {\n        const num = this.peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        this.#front = this.#front.next;\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek() {\n        if (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.#front.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray() {\n        let node = this.#front;\n        const res = new Array(this.size);\n        for (let i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_queue.ts
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    private front: ListNode | null; // \u5934\u8282\u70b9 front\n    private rear: ListNode | null; // \u5c3e\u8282\u70b9 rear\n    private queSize: number = 0;\n\n    constructor() {\n        this.front = null;\n        this.rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.size === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num: number): void {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        const 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\n        if (!this.front) {\n            this.front = node;\n            this.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 {\n            this.rear!.next = node;\n            this.rear = node;\n        }\n        this.queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop(): number {\n        const num = this.peek();\n        if (!this.front) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        // \u5220\u9664\u5934\u8282\u70b9\n        this.front = this.front.next;\n        this.queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek(): number {\n        if (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.front!.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray(): number[] {\n        let node = this.front;\n        const res = new Array<number>(this.size);\n        for (let i = 0; i < res.length; i++) {\n            res[i] = node!.val;\n            node = node!.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_queue.dart
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n  ListNode? _front; // \u5934\u8282\u70b9 _front\n  ListNode? _rear; // \u5c3e\u8282\u70b9 _rear\n  int _queSize = 0; // \u961f\u5217\u957f\u5ea6\n\n  LinkedListQueue() {\n    _front = null;\n    _rear = null;\n  }\n\n  /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n  int size() {\n    return _queSize;\n  }\n\n  /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _queSize == 0;\n  }\n\n  /* \u5165\u961f */\n  void push(int _num) {\n    // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 _num\n    final node = ListNode(_num);\n    // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n    if (_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\n  /* \u51fa\u961f */\n  int pop() {\n    final int _num = peek();\n    // \u5220\u9664\u5934\u8282\u70b9\n    _front = _front!.next;\n    _queSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int peek() {\n    if (_queSize == 0) {\n      throw Exception('\u961f\u5217\u4e3a\u7a7a');\n    }\n    return _front!.val;\n  }\n\n  /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n  List<int> toArray() {\n    ListNode? node = _front;\n    final List<int> queue = [];\n    while (node != null) {\n      queue.add(node.val);\n      node = node.next;\n    }\n    return queue;\n  }\n}\n
    linkedlist_queue.rs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\n#[allow(dead_code)]\npub struct LinkedListQueue<T> {\n    front: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\n    rear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \n    que_size: usize,                            // \u961f\u5217\u7684\u957f\u5ea6\n}\n\nimpl<T: Copy> LinkedListQueue<T> {\n    pub fn new() -> Self {\n        Self {\n            front: None,\n            rear: None,\n            que_size: 0, \n        }\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        return self.que_size;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        return self.size() == 0;\n    }\n\n    /* \u5165\u961f */\n    pub fn push(&mut self, num: T) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        let new_rear = ListNode::new(num);\n        match self.rear.take() {\n            // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n            Some(old_rear) => {\n                old_rear.borrow_mut().next = Some(new_rear.clone());\n                self.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\n            None => {\n                self.front = Some(new_rear.clone());\n                self.rear = Some(new_rear);\n            }\n        }\n        self.que_size += 1;\n    }\n\n    /* \u51fa\u961f */\n    pub fn pop(&mut self) -> Option<T> {\n        self.front.take().map(|old_front| {\n            match old_front.borrow_mut().next.take() {\n                Some(new_front) => {\n                    self.front = Some(new_front);\n                }\n                None => {\n                    self.rear.take();\n                }\n            }\n            self.que_size -= 1;\n            Rc::try_unwrap(old_front).ok().unwrap().into_inner().val\n        })\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    pub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.front.as_ref()\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\n        if let Some(node) = head {\n            let mut nums = self.to_array(node.borrow().next.as_ref());\n            nums.insert(0, node.borrow().val);\n            return nums;\n        }\n        return Vec::new();\n    }\n}\n
    linkedlist_queue.c
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\n    ListNode *front, *rear;\n    int queSize;\n} LinkedListQueue;\n\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListQueue *newLinkedListQueue() {\n    LinkedListQueue *queue = (LinkedListQueue *)malloc(sizeof(LinkedListQueue));\n    queue->front = NULL;\n    queue->rear = NULL;\n    queue->queSize = 0;\n    return queue;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListQueue(LinkedListQueue *queue) {\n    // \u91ca\u653e\u6240\u6709\u8282\u70b9\n    for (int i = 0; i < queue->queSize && queue->front != NULL; i++) {\n        ListNode *tmp = queue->front;\n        queue->front = queue->front->next;\n        free(tmp);\n    }\n    // \u91ca\u653e queue \u7ed3\u6784\u4f53\n    free(queue);\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListQueue *queue) {\n    return queue->queSize;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListQueue *queue) {\n    return (size(queue) == 0);\n}\n\n/* \u5165\u961f */\nvoid push(LinkedListQueue *queue, int num) {\n    // \u5c3e\u8282\u70b9\u5904\u6dfb\u52a0 node\n    ListNode *node = newListNode(num);\n    // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n    if (queue->front == NULL) {\n        queue->front = node;\n        queue->rear = node;\n    }\n    // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n    else {\n        queue->rear->next = node;\n        queue->rear = node;\n    }\n    queue->queSize++;\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(LinkedListQueue *queue) {\n    assert(size(queue) && queue->front);\n    return queue->front->val;\n}\n\n/* \u51fa\u961f */\nint pop(LinkedListQueue *queue) {\n    int num = peek(queue);\n    ListNode *tmp = queue->front;\n    queue->front = queue->front->next;\n    free(tmp);\n    queue->queSize--;\n    return num;\n}\n\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListQueue(LinkedListQueue *queue) {\n    int *arr = malloc(sizeof(int) * queue->queSize);\n    // \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\n    int i;\n    ListNode *node;\n    for (i = 0, node = queue->front; i < queue->queSize; i++) {\n        arr[i] = node->val;\n        node = node->next;\n    }\n    printArray(arr, queue->queSize);\n    free(arr);\n}\n
    linkedlist_queue.zig
    // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217\nfn LinkedListQueue(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        front: ?*inc.ListNode(T) = null,                // \u5934\u8282\u70b9 front\n        rear: ?*inc.ListNode(T) = null,                 // \u5c3e\u8282\u70b9 rear\n        que_size: usize = 0,                            // \u961f\u5217\u7684\u957f\u5ea6\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.front = null;\n            self.rear = null;\n            self.que_size = 0;\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.que_size;\n        }\n\n        // \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.size() == 0) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\n            return self.front.?.val;\n        }  \n\n        // \u5165\u961f\n        pub fn push(self: *Self, num: T) !void {\n            // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n            var node = try self.mem_allocator.create(inc.ListNode(T));\n            node.init(num);\n            // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n            if (self.front == null) {\n                self.front = node;\n                self.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 {\n                self.rear.?.next = node;\n                self.rear = node;\n            }\n            self.que_size += 1;\n        } \n\n        // \u51fa\u961f\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            // \u5220\u9664\u5934\u8282\u70b9\n            self.front = self.front.?.next;\n            self.que_size -= 1;\n            return num;\n        } \n\n        // \u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            var node = self.front;\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            while (i < res.len) : (i += 1) {\n                res[i] = node.?.val;\n                node = node.?.next;\n            }\n            return 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\"\"\"\n\n    def __init__(self, size: int):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._nums: list[int] = [0] * size  # \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n        self._front: int = 0  # \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n        self._size: int = 0  # \u961f\u5217\u957f\u5ea6\n\n    def capacity(self) -> int:\n        \"\"\"\u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\n        return len(self._nums)\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self._size == 0\n\n    def push(self, num: int):\n        \"\"\"\u5165\u961f\"\"\"\n        if self._size == self.capacity():\n            raise IndexError(\"\u961f\u5217\u5df2\u6ee1\")\n        # \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        # \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        rear: int = (self._front + self._size) % self.capacity()\n        # \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self._nums[rear] = num\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u961f\"\"\"\n        num: int = self.peek()\n        # \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        self._front = (self._front + 1) % self.capacity()\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\n        return self._nums[self._front]\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        res = [0] * self.size()\n        j: int = self._front\n        for i in range(self.size()):\n            res[i] = self._nums[(j % self.capacity())]\n            j += 1\n        return res\n
    array_queue.cpp
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n  private:\n    int *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;     // \u961f\u5217\u957f\u5ea6\n    int queCapacity; // \u961f\u5217\u5bb9\u91cf\n\n  public:\n    ArrayQueue(int capacity) {\n        // \u521d\u59cb\u5316\u6570\u7ec4\n        nums = new int[capacity];\n        queCapacity = capacity;\n        front = queSize = 0;\n    }\n\n    ~ArrayQueue() {\n        delete[] nums;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    int capacity() {\n        return queCapacity;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f */\n    void push(int num) {\n        if (queSize == queCapacity) {\n            cout << \"\u961f\u5217\u5df2\u6ee1\" << endl;\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        int rear = (front + queSize) % queCapacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    int pop() {\n        int num = peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % queCapacity;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peek() {\n        if (isEmpty())\n            throw out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\n        return nums[front];\n    }\n\n    /* \u5c06\u6570\u7ec4\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\n    vector<int> toVector() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        vector<int> arr(queSize);\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            arr[i] = nums[j % queCapacity];\n        }\n        return arr;\n    }\n};\n
    array_queue.java
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    private int[] nums; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private int queSize; // \u961f\u5217\u957f\u5ea6\n\n    public ArrayQueue(int capacity) {\n        nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    public int capacity() {\n        return nums.length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u5165\u961f */\n    public void push(int num) {\n        if (queSize == capacity()) {\n            System.out.println(\"\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        int rear = (front + queSize) % capacity();\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int pop() {\n        int num = peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % capacity();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return nums[front];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    public int[] toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[j % capacity()];\n        }\n        return res;\n    }\n}\n
    array_queue.cs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    int[] nums;  // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize; // \u961f\u5217\u957f\u5ea6\n\n    public ArrayQueue(int capacity) {\n        nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    int Capacity() {\n        return nums.Length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u5165\u961f */\n    public void Push(int num) {\n        if (queSize == Capacity()) {\n            Console.WriteLine(\"\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        int rear = (front + queSize) % Capacity();\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int Pop() {\n        int num = Peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % Capacity();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return nums[front];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    public int[] ToArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[j % this.Capacity()];\n        }\n        return res;\n    }\n}\n
    array_queue.go
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntype arrayQueue struct {\n    nums        []int // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    queSize     int   // \u961f\u5217\u957f\u5ea6\n    queCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayQueue(queCapacity int) *arrayQueue {\n    return &arrayQueue{\n        nums:        make([]int, queCapacity),\n        queCapacity: queCapacity,\n        front:       0,\n        queSize:     0,\n    }\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayQueue) size() int {\n    return q.queSize\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayQueue) isEmpty() bool {\n    return q.queSize == 0\n}\n\n/* \u5165\u961f */\nfunc (q *arrayQueue) push(num int) {\n    // \u5f53 rear == queCapacity \u8868\u793a\u961f\u5217\u5df2\u6ee1\n    if q.queSize == q.queCapacity {\n        return\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n    rear := (q.front + q.queSize) % q.queCapacity\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    q.nums[rear] = num\n    q.queSize++\n}\n\n/* \u51fa\u961f */\nfunc (q *arrayQueue) pop() any {\n    num := q.peek()\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n    q.front = (q.front + 1) % q.queCapacity\n    q.queSize--\n    return num\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayQueue) peek() any {\n    if q.isEmpty() {\n        return nil\n    }\n    return q.nums[q.front]\n}\n\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (q *arrayQueue) toSlice() []int {\n    rear := (q.front + q.queSize)\n    if rear >= q.queCapacity {\n        rear %= q.queCapacity\n        return append(q.nums[q.front:], q.nums[:rear]...)\n    }\n    return q.nums[q.front:rear]\n}\n
    array_queue.swift
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    private var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private var front = 0 // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private var queSize = 0 // \u961f\u5217\u957f\u5ea6\n\n    init(capacity: Int) {\n        // \u521d\u59cb\u5316\u6570\u7ec4\n        nums = Array(repeating: 0, count: capacity)\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    func capacity() -> Int {\n        nums.count\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        queSize\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        queSize == 0\n    }\n\n    /* \u5165\u961f */\n    func push(num: Int) {\n        if size() == capacity() {\n            print(\"\u961f\u5217\u5df2\u6ee1\")\n            return\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        let rear = (front + queSize) % capacity()\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num\n        queSize += 1\n    }\n\n    /* \u51fa\u961f */\n    @discardableResult\n    func pop() -> Int {\n        let num = peek()\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % capacity()\n        queSize -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n        }\n        return nums[front]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    func toArray() -> [Int] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        var res = Array(repeating: 0, count: queSize)\n        for (i, j) in sequence(first: (0, front), next: { $0 < self.queSize - 1 ? ($0 + 1, $1 + 1) : nil }) {\n            res[i] = nums[j % capacity()]\n        }\n        return 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\n\n    constructor(capacity) {\n        this.#nums = new Array(capacity);\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    get capacity() {\n        return this.#nums.length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#queSize === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num) {\n        if (this.size === this.capacity) {\n            console.log('\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        const rear = (this.#front + this.size) % this.capacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.#nums[rear] = num;\n        this.#queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop() {\n        const num = this.peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        this.#front = (this.#front + 1) % this.capacity;\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek() {\n        if (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.#nums[this.#front];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(this.size);\n        for (let i = 0, j = this.#front; i < this.size; i++, j++) {\n            arr[i] = this.#nums[j % this.capacity];\n        }\n        return arr;\n    }\n}\n
    array_queue.ts
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    private nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private queSize: number; // \u961f\u5217\u957f\u5ea6\n\n    constructor(capacity: number) {\n        this.nums = new Array(capacity);\n        this.front = this.queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    get capacity(): number {\n        return this.nums.length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.queSize === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num: number): void {\n        if (this.size === this.capacity) {\n            console.log('\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        const rear = (this.front + this.queSize) % this.capacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.nums[rear] = num;\n        this.queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop(): number {\n        const num = this.peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        this.front = (this.front + 1) % this.capacity;\n        this.queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek(): number {\n        if (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.nums[this.front];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray(): number[] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(this.size);\n        for (let i = 0, j = this.front; i < this.size; i++, j++) {\n            arr[i] = this.nums[j % this.capacity];\n        }\n        return arr;\n    }\n}\n
    array_queue.dart
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n  late List<int> _nums; // \u7528\u4e8e\u50a8\u5b58\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n  late int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n  late int _queSize; // \u961f\u5217\u957f\u5ea6\n\n  ArrayQueue(int capacity) {\n    _nums = List.filled(capacity, 0);\n    _front = _queSize = 0;\n  }\n\n  /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n  int capaCity() {\n    return _nums.length;\n  }\n\n  /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n  int size() {\n    return _queSize;\n  }\n\n  /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _queSize == 0;\n  }\n\n  /* \u5165\u961f */\n  void push(int _num) {\n    if (_queSize == capaCity()) {\n      throw Exception(\"\u961f\u5217\u5df2\u6ee1\");\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n    int rear = (_front + _queSize) % capaCity();\n    // \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    _nums[rear] = _num;\n    _queSize++;\n  }\n\n  /* \u51fa\u961f */\n  int pop() {\n    int _num = peek();\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n    _front = (_front + 1) % capaCity();\n    _queSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int peek() {\n    if (isEmpty()) {\n      throw Exception(\"\u961f\u5217\u4e3a\u7a7a\");\n    }\n    return _nums[_front];\n  }\n\n  /* \u8fd4\u56de Array */\n  List<int> toArray() {\n    // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n    final List<int> res = List.filled(_queSize, 0);\n    for (int i = 0, j = _front; i < _queSize; i++, j++) {\n      res[i] = _nums[j % capaCity()];\n    }\n    return res;\n  }\n}\n
    array_queue.rs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nstruct ArrayQueue {\n    nums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front: i32,         // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    que_size: i32,      // \u961f\u5217\u957f\u5ea6\n    que_capacity: i32,  // \u961f\u5217\u5bb9\u91cf\n}\n\nimpl ArrayQueue {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(capacity: i32) -> ArrayQueue {\n        ArrayQueue {\n            nums: vec![0; capacity as usize],\n            front: 0,\n            que_size: 0,\n            que_capacity: capacity,\n        }\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    fn capacity(&self) -> i32 {\n        self.que_capacity\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    fn size(&self) -> i32 {\n        self.que_size\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    fn is_empty(&self) -> bool {\n        self.que_size == 0\n    }\n\n    /* \u5165\u961f */\n    fn push(&mut self, num: i32) {\n        if self.que_size == self.capacity() {\n            println!(\"\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        let rear = (self.front + self.que_size) % self.que_capacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self.nums[rear as usize] = num;\n        self.que_size += 1;\n    }\n\n    /* \u51fa\u961f */\n    fn pop(&mut self) -> i32 {\n        let num = self.peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        self.front = (self.front + 1) % self.que_capacity;\n        self.que_size -= 1;\n        num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    fn peek(&self) -> i32 {\n        if self.is_empty() {\n            panic!(\"index out of bounds\");\n        }\n        self.nums[self.front as usize]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    fn to_vector(&self) -> Vec<i32> {\n        let cap = self.que_capacity;\n        let mut j = self.front;\n        let mut arr = vec![0; self.que_size as usize];\n        for i in 0..self.que_size {\n            arr[i as usize] = self.nums[(j % cap) as usize];\n            j += 1;\n        }\n        arr\n    }\n}\n
    array_queue.c
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\n    int *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\n    int queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayQueue;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayQueue *newArrayQueue(int capacity) {\n    ArrayQueue *queue = (ArrayQueue *)malloc(sizeof(ArrayQueue));\n    // \u521d\u59cb\u5316\u6570\u7ec4\n    queue->queCapacity = capacity;\n    queue->nums = (int *)malloc(sizeof(int) * queue->queCapacity);\n    queue->front = queue->queSize = 0;\n    return queue;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayQueue(ArrayQueue *queue) {\n    free(queue->nums);\n    free(queue);\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayQueue *queue) {\n    return queue->queCapacity;\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayQueue *queue) {\n    return queue->queSize;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayQueue *queue) {\n    return queue->queSize == 0;\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(ArrayQueue *queue) {\n    assert(size(queue) != 0);\n    return queue->nums[queue->front];\n}\n\n/* \u5165\u961f */\nvoid push(ArrayQueue *queue, int num) {\n    if (size(queue) == capacity(queue)) {\n        printf(\"\u961f\u5217\u5df2\u6ee1\\r\\n\");\n        return;\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n    int rear = (queue->front + queue->queSize) % queue->queCapacity;\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    queue->nums[rear] = num;\n    queue->queSize++;\n}\n\n/* \u51fa\u961f */\nint pop(ArrayQueue *queue) {\n    int num = peek(queue);\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n    queue->front = (queue->front + 1) % queue->queCapacity;\n    queue->queSize--;\n    return num;\n}\n
    array_queue.zig
    // \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217\nfn ArrayQueue(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        nums: []T = undefined,                          // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4     \n        cap: usize = 0,                                 // \u961f\u5217\u5bb9\u91cf\n        front: usize = 0,                               // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n        queSize: usize = 0,                             // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6570\u7ec4\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator, cap: usize) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.cap = cap;\n            self.nums = try self.mem_allocator.alloc(T, self.cap);\n            @memset(self.nums, @as(T, 0));\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\n        pub fn capacity(self: *Self) usize {\n            return self.cap;\n        }\n\n        // \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.queSize;\n        }\n\n        // \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.queSize == 0;\n        }\n\n        // \u5165\u961f\n        pub fn push(self: *Self, num: T) !void {\n            if (self.size() == self.capacity()) {\n                std.debug.print(\"\u961f\u5217\u5df2\u6ee1\\n\", .{});\n                return;\n            }\n            // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n            // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n            var rear = (self.front + self.queSize) % self.capacity();\n            // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n            self.nums[rear] = num;\n            self.queSize += 1;\n        } \n\n        // \u51fa\u961f\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n            self.front = (self.front + 1) % self.capacity();\n            self.queSize -= 1;\n            return num;\n        } \n\n        // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\n            return self.nums[self.front];\n        } \n\n        // \u8fd4\u56de\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            var j: usize = self.front;\n            while (i < self.size()) : ({ i += 1; j += 1; }) {\n                res[i] = self.nums[j % self.capacity()];\n            }\n            return 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\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\u7684\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\n# \u5143\u7d20\u5165\u6808\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n\n# \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npeek: int = stack[-1]\n\n# \u5143\u7d20\u51fa\u6808\npop: int = stack.pop()\n\n# \u83b7\u53d6\u6808\u7684\u957f\u5ea6\nsize: int = len(stack)\n\n# \u5224\u65ad\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(stack) == 0\n
    stack.cpp
    /* \u521d\u59cb\u5316\u6808 */\nstack<int> stack;\n\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top = stack.top();\n\n/* \u5143\u7d20\u51fa\u6808 */\nstack.pop(); // \u65e0\u8fd4\u56de\u503c\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool empty = stack.empty();\n
    stack.java
    /* \u521d\u59cb\u5316\u6808 */\nStack<Integer> stack = new Stack<>();\n\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.peek();\n\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = stack.isEmpty();\n
    stack.cs
    /* \u521d\u59cb\u5316\u6808 */\nStack<int> stack = new();\n\n/* \u5143\u7d20\u5165\u6808 */\nstack.Push(1);\nstack.Push(3);\nstack.Push(2);\nstack.Push(5);\nstack.Push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.Peek();\n\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.Pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.Count;\n\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\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\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek := stack[len(stack)-1]\n\n/* \u5143\u7d20\u51fa\u6808 */\npop := stack[len(stack)-1]\nstack = stack[:len(stack)-1]\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nsize := len(stack)\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet peek = stack.last!\n\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.removeLast()\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.count\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length-1];\n\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length - 1];\n\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.add(1);\nstack.add(3);\nstack.add(2);\nstack.add(5);\nstack.add(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.last;\n\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.removeLast();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.length;\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet top = stack.last().unwrap();\n\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.pop().unwrap();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.len();\n\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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._peek: ListNode | None = None\n        self._size: int = 0\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return not self._peek\n\n    def push(self, val: int):\n        \"\"\"\u5165\u6808\"\"\"\n        node = ListNode(val)\n        node.next = self._peek\n        self._peek = node\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u6808\"\"\"\n        num = self.peek()\n        self._peek = self._peek.next\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u6808\u4e3a\u7a7a\")\n        return self._peek.val\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        arr = []\n        node = self._peek\n        while node:\n            arr.append(node.val)\n            node = node.next\n        arr.reverse()\n        return arr\n
    linkedlist_stack.cpp
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n  private:\n    ListNode *stackTop; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    int stkSize;        // \u6808\u7684\u957f\u5ea6\n\n  public:\n    LinkedListStack() {\n        stackTop = nullptr;\n        stkSize = 0;\n    }\n\n    ~LinkedListStack() {\n        // \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n        freeMemoryLinkedList(stackTop);\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    int size() {\n        return stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    void push(int num) {\n        ListNode *node = new ListNode(num);\n        node->next = stackTop;\n        stackTop = node;\n        stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    int pop() {\n        int num = top();\n        ListNode *tmp = stackTop;\n        stackTop = stackTop->next;\n        // \u91ca\u653e\u5185\u5b58\n        delete tmp;\n        stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    int top() {\n        if (isEmpty())\n            throw out_of_range(\"\u6808\u4e3a\u7a7a\");\n        return stackTop->val;\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    vector<int> toVector() {\n        ListNode *node = stackTop;\n        vector<int> res(size());\n        for (int i = res.size() - 1; i >= 0; i--) {\n            res[i] = node->val;\n            node = node->next;\n        }\n        return res;\n    }\n};\n
    linkedlist_stack.java
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    private ListNode stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    private int stkSize = 0; // \u6808\u7684\u957f\u5ea6\n\n    public LinkedListStack() {\n        stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int size() {\n        return stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void push(int num) {\n        ListNode node = new ListNode(num);\n        node.next = stackPeek;\n        stackPeek = node;\n        stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    public int pop() {\n        int num = peek();\n        stackPeek = stackPeek.next;\n        stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return stackPeek.val;\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] toArray() {\n        ListNode node = stackPeek;\n        int[] res = new int[size()];\n        for (int i = res.length - 1; i >= 0; i--) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_stack.cs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    ListNode? stackPeek;  // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    int stkSize = 0;   // \u6808\u7684\u957f\u5ea6\n\n    public LinkedListStack() {\n        stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int Size() {\n        return stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void Push(int num) {\n        ListNode node = new(num) {\n            next = stackPeek\n        };\n        stackPeek = node;\n        stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    public int Pop() {\n        int num = Peek();\n        stackPeek = stackPeek!.next;\n        stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return stackPeek!.val;\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] ToArray() {\n        if (stackPeek == null)\n            return [];\n\n        ListNode? node = stackPeek;\n        int[] res = new int[Size()];\n        for (int i = res.Length - 1; i >= 0; i--) {\n            res[i] = node!.val;\n            node = node.next;\n        }\n        return 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\n    data *list.List\n}\n\n/* \u521d\u59cb\u5316\u6808 */\nfunc newLinkedListStack() *linkedListStack {\n    return &linkedListStack{\n        data: list.New(),\n    }\n}\n\n/* \u5165\u6808 */\nfunc (s *linkedListStack) push(value int) {\n    s.data.PushBack(value)\n}\n\n/* \u51fa\u6808 */\nfunc (s *linkedListStack) pop() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc (s *linkedListStack) peek() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    return e.Value\n}\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc (s *linkedListStack) size() int {\n    return s.data.Len()\n}\n\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListStack) isEmpty() bool {\n    return s.data.Len() == 0\n}\n\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListStack) toList() *list.List {\n    return s.data\n}\n
    linkedlist_stack.swift
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    private var _peek: ListNode? // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    private var _size = 0 // \u6808\u7684\u957f\u5ea6\n\n    init() {}\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        _size\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u5165\u6808 */\n    func push(num: Int) {\n        let node = ListNode(x: num)\n        node.next = _peek\n        _peek = node\n        _size += 1\n    }\n\n    /* \u51fa\u6808 */\n    @discardableResult\n    func pop() -> Int {\n        let num = peek()\n        _peek = _peek?.next\n        _size -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u6808\u4e3a\u7a7a\")\n        }\n        return _peek!.val\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    func toArray() -> [Int] {\n        var node = _peek\n        var res = Array(repeating: 0, count: _size)\n        for i in sequence(first: res.count - 1, next: { $0 >= 0 + 1 ? $0 - 1 : nil }) {\n            res[i] = node!.val\n            node = node?.next\n        }\n        return 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\n\n    constructor() {\n        this.#stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.size === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num) {\n        const node = new ListNode(num);\n        node.next = this.#stackPeek;\n        this.#stackPeek = node;\n        this.#stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    pop() {\n        const num = this.peek();\n        this.#stackPeek = this.#stackPeek.next;\n        this.#stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    peek() {\n        if (!this.#stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.#stackPeek.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray() {\n        let node = this.#stackPeek;\n        const res = new Array(this.size);\n        for (let i = res.length - 1; i >= 0; i--) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_stack.ts
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    private stackPeek: ListNode | null; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    private stkSize: number = 0; // \u6808\u7684\u957f\u5ea6\n\n    constructor() {\n        this.stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.size === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num: number): void {\n        const node = new ListNode(num);\n        node.next = this.stackPeek;\n        this.stackPeek = node;\n        this.stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    pop(): number {\n        const num = this.peek();\n        if (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\n        this.stackPeek = this.stackPeek.next;\n        this.stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    peek(): number {\n        if (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.stackPeek.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray(): number[] {\n        let node = this.stackPeek;\n        const res = new Array<number>(this.size);\n        for (let i = res.length - 1; i >= 0; i--) {\n            res[i] = node!.val;\n            node = node!.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_stack.dart
    /* \u57fa\u4e8e\u94fe\u8868\u7c7b\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n  ListNode? _stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n  int _stkSize = 0; // \u6808\u7684\u957f\u5ea6\n\n  LinkedListStack() {\n    _stackPeek = null;\n  }\n\n  /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n  int size() {\n    return _stkSize;\n  }\n\n  /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _stkSize == 0;\n  }\n\n  /* \u5165\u6808 */\n  void push(int _num) {\n    final ListNode node = ListNode(_num);\n    node.next = _stackPeek;\n    _stackPeek = node;\n    _stkSize++;\n  }\n\n  /* \u51fa\u6808 */\n  int pop() {\n    final int _num = peek();\n    _stackPeek = _stackPeek!.next;\n    _stkSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n  int peek() {\n    if (_stackPeek == null) {\n      throw Exception(\"\u6808\u4e3a\u7a7a\");\n    }\n    return _stackPeek!.val;\n  }\n\n  /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a List \u5e76\u8fd4\u56de */\n  List<int> toList() {\n    ListNode? node = _stackPeek;\n    List<int> list = [];\n    while (node != null) {\n      list.add(node.val);\n      node = node.next;\n    }\n    list = list.reversed.toList();\n    return list;\n  }\n}\n
    linkedlist_stack.rs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\n#[allow(dead_code)]\npub struct LinkedListStack<T> {\n    stack_peek: Option<Rc<RefCell<ListNode<T>>>>,   // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    stk_size: usize,                                // \u6808\u7684\u957f\u5ea6\n}\n\nimpl<T: Copy> LinkedListStack<T> {\n    pub fn new() -> Self {\n        Self {\n            stack_peek: None,\n            stk_size: 0,\n        }\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        return self.stk_size;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        return self.size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    pub fn push(&mut self, num: T) {\n        let node = ListNode::new(num);\n        node.borrow_mut().next = self.stack_peek.take();\n        self.stack_peek = Some(node);\n        self.stk_size += 1;\n    }\n\n    /* \u51fa\u6808 */\n    pub fn pop(&mut self) -> Option<T> {\n        self.stack_peek.take().map(|old_head| {\n            match old_head.borrow_mut().next.take() {\n                Some(new_head) => {\n                    self.stack_peek = Some(new_head);\n                }\n                None => {\n                    self.stack_peek = None;\n                }\n            }\n            self.stk_size -= 1;\n            Rc::try_unwrap(old_head).ok().unwrap().into_inner().val\n        })\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    pub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.stack_peek.as_ref()\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\n        if let Some(node) = head {\n            let mut nums = self.to_array(node.borrow().next.as_ref());\n            nums.push(node.borrow().val);\n            return nums;\n        }\n        return Vec::new();\n    }\n}\n
    linkedlist_stack.c
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\n    ListNode *top; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    int size;      // \u6808\u7684\u957f\u5ea6\n} LinkedListStack;\n\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListStack *newLinkedListStack() {\n    LinkedListStack *s = malloc(sizeof(LinkedListStack));\n    s->top = NULL;\n    s->size = 0;\n    return s;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListStack(LinkedListStack *s) {\n    while (s->top) {\n        ListNode *n = s->top->next;\n        free(s->top);\n        s->top = n;\n    }\n    free(s);\n}\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(LinkedListStack *s) {\n    return s->size;\n}\n\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(LinkedListStack *s) {\n    return size(s) == 0;\n}\n\n/* \u5165\u6808 */\nvoid push(LinkedListStack *s, int num) {\n    ListNode *node = (ListNode *)malloc(sizeof(ListNode));\n    node->next = s->top; // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6307\u9488\u57df\n    node->val = num;     // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6570\u636e\u57df\n    s->top = node;       // \u66f4\u65b0\u6808\u9876\n    s->size++;           // \u66f4\u65b0\u6808\u5927\u5c0f\n}\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(LinkedListStack *s) {\n    if (s->size == 0) {\n        printf(\"\u6808\u4e3a\u7a7a\\n\");\n        return INT_MAX;\n    }\n    return s->top->val;\n}\n\n/* \u51fa\u6808 */\nint pop(LinkedListStack *s) {\n    int val = peek(s);\n    ListNode *tmp = s->top;\n    s->top = s->top->next;\n    // \u91ca\u653e\u5185\u5b58\n    free(tmp);\n    s->size--;\n    return val;\n}\n
    linkedlist_stack.zig
    // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\nfn LinkedListStack(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        stack_top: ?*inc.ListNode(T) = null,             // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n        stk_size: usize = 0,                             // \u6808\u7684\u957f\u5ea6\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,    // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.stack_top = null;\n            self.stk_size = 0;\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u6808\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.stk_size;\n        }\n\n        // \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u8bbf\u95ee\u6808\u9876\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.size() == 0) @panic(\"\u6808\u4e3a\u7a7a\");\n            return self.stack_top.?.val;\n        }  \n\n        // \u5165\u6808\n        pub fn push(self: *Self, num: T) !void {\n            var node = try self.mem_allocator.create(inc.ListNode(T));\n            node.init(num);\n            node.next = self.stack_top;\n            self.stack_top = node;\n            self.stk_size += 1;\n        } \n\n        // \u51fa\u6808\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            self.stack_top = self.stack_top.?.next;\n            self.stk_size -= 1;\n            return num;\n        } \n\n        // \u5c06\u6808\u8f6c\u6362\u4e3a\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            var node = self.stack_top;\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            while (i < res.len) : (i += 1) {\n                res[res.len - i - 1] = node.?.val;\n                node = node.?.next;\n            }\n            return 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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._stack: list[int] = []\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\n        return len(self._stack)\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self._stack == []\n\n    def push(self, item: int):\n        \"\"\"\u5165\u6808\"\"\"\n        self._stack.append(item)\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u6808\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u6808\u4e3a\u7a7a\")\n        return self._stack.pop()\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u6808\u4e3a\u7a7a\")\n        return self._stack[-1]\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        return self._stack\n
    array_stack.cpp
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n  private:\n    vector<int> stack;\n\n  public:\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    int size() {\n        return stack.size();\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return stack.size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    void push(int num) {\n        stack.push_back(num);\n    }\n\n    /* \u51fa\u6808 */\n    int pop() {\n        int num = top();\n        stack.pop_back();\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    int top() {\n        if (isEmpty())\n            throw out_of_range(\"\u6808\u4e3a\u7a7a\");\n        return stack.back();\n    }\n\n    /* \u8fd4\u56de Vector */\n    vector<int> toVector() {\n        return stack;\n    }\n};\n
    array_stack.java
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    private ArrayList<Integer> stack;\n\n    public ArrayStack() {\n        // \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\n        stack = new ArrayList<>();\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int size() {\n        return stack.size();\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void push(int num) {\n        stack.add(num);\n    }\n\n    /* \u51fa\u6808 */\n    public int pop() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return stack.remove(size() - 1);\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return stack.get(size() - 1);\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public Object[] toArray() {\n        return stack.toArray();\n    }\n}\n
    array_stack.cs
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    List<int> stack;\n    public ArrayStack() {\n        // \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\n        stack = [];\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int Size() {\n        return stack.Count;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void Push(int num) {\n        stack.Add(num);\n    }\n\n    /* \u51fa\u6808 */\n    public int Pop() {\n        if (IsEmpty())\n            throw new Exception();\n        var val = Peek();\n        stack.RemoveAt(Size() - 1);\n        return val;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return stack[Size() - 1];\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] ToArray() {\n        return [.. stack];\n    }\n}\n
    array_stack.go
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntype arrayStack struct {\n    data []int // \u6570\u636e\n}\n\n/* \u521d\u59cb\u5316\u6808 */\nfunc newArrayStack() *arrayStack {\n    return &arrayStack{\n        // \u8bbe\u7f6e\u6808\u7684\u957f\u5ea6\u4e3a 0\uff0c\u5bb9\u91cf\u4e3a 16\n        data: make([]int, 0, 16),\n    }\n}\n\n/* \u6808\u7684\u957f\u5ea6 */\nfunc (s *arrayStack) size() int {\n    return len(s.data)\n}\n\n/* \u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *arrayStack) isEmpty() bool {\n    return s.size() == 0\n}\n\n/* \u5165\u6808 */\nfunc (s *arrayStack) push(v int) {\n    // \u5207\u7247\u4f1a\u81ea\u52a8\u6269\u5bb9\n    s.data = append(s.data, v)\n}\n\n/* \u51fa\u6808 */\nfunc (s *arrayStack) pop() any {\n    val := s.peek()\n    s.data = s.data[:len(s.data)-1]\n    return val\n}\n\n/* \u83b7\u53d6\u6808\u9876\u5143\u7d20 */\nfunc (s *arrayStack) peek() any {\n    if s.isEmpty() {\n        return nil\n    }\n    val := s.data[len(s.data)-1]\n    return val\n}\n\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (s *arrayStack) toSlice() []int {\n    return s.data\n}\n
    array_stack.swift
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    private var stack: [Int]\n\n    init() {\n        // \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\n        stack = []\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        stack.count\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        stack.isEmpty\n    }\n\n    /* \u5165\u6808 */\n    func push(num: Int) {\n        stack.append(num)\n    }\n\n    /* \u51fa\u6808 */\n    @discardableResult\n    func pop() -> Int {\n        if isEmpty() {\n            fatalError(\"\u6808\u4e3a\u7a7a\")\n        }\n        return stack.removeLast()\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u6808\u4e3a\u7a7a\")\n        }\n        return stack.last!\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    func toArray() -> [Int] {\n        stack\n    }\n}\n
    array_stack.js
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    #stack;\n    constructor() {\n        this.#stack = [];\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#stack.length;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#stack.length === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num) {\n        this.#stack.push(num);\n    }\n\n    /* \u51fa\u6808 */\n    pop() {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.#stack.pop();\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    top() {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.#stack[this.#stack.length - 1];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray() {\n        return this.#stack;\n    }\n}\n
    array_stack.ts
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    private stack: number[];\n    constructor() {\n        this.stack = [];\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.stack.length;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.stack.length === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num: number): void {\n        this.stack.push(num);\n    }\n\n    /* \u51fa\u6808 */\n    pop(): number | undefined {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.stack.pop();\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    top(): number | undefined {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.stack[this.stack.length - 1];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray() {\n        return this.stack;\n    }\n}\n
    array_stack.dart
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n  late List<int> _stack;\n  ArrayStack() {\n    _stack = [];\n  }\n\n  /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n  int size() {\n    return _stack.length;\n  }\n\n  /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _stack.isEmpty;\n  }\n\n  /* \u5165\u6808 */\n  void push(int _num) {\n    _stack.add(_num);\n  }\n\n  /* \u51fa\u6808 */\n  int pop() {\n    if (isEmpty()) {\n      throw Exception(\"\u6808\u4e3a\u7a7a\");\n    }\n    return _stack.removeLast();\n  }\n\n  /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n  int peek() {\n    if (isEmpty()) {\n      throw Exception(\"\u6808\u4e3a\u7a7a\");\n    }\n    return _stack.last;\n  }\n\n  /* \u5c06\u6808\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n  List<int> toArray() => _stack;\n}\n
    array_stack.rs
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nstruct ArrayStack<T> {\n    stack: Vec<T>,\n}\n\nimpl<T> ArrayStack<T> {\n    /* \u521d\u59cb\u5316\u6808 */\n    fn new() -> ArrayStack<T> {\n        ArrayStack::<T> { stack: Vec::<T>::new() }\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    fn size(&self) -> usize {\n        self.stack.len()\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    fn is_empty(&self) -> bool {\n        self.size() == 0\n    }\n\n    /* \u5165\u6808 */\n    fn push(&mut self, num: T) {\n        self.stack.push(num);\n    }\n\n    /* \u51fa\u6808 */\n    fn pop(&mut self) -> Option<T> {\n        match self.stack.pop() {\n            Some(num) => Some(num),\n            None => None,\n        }\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    fn peek(&self) -> Option<&T> {\n        if self.is_empty() { panic!(\"\u6808\u4e3a\u7a7a\") };\n        self.stack.last()\n    }\n\n    /* \u8fd4\u56de &Vec */\n    fn to_array(&self) -> &Vec<T> {\n        &self.stack\n    }\n}\n
    array_stack.c
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\n    int *data;\n    int size;\n} ArrayStack;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayStack *newArrayStack() {\n    ArrayStack *stack = malloc(sizeof(ArrayStack));\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5927\u5bb9\u91cf\uff0c\u907f\u514d\u6269\u5bb9\n    stack->data = malloc(sizeof(int) * MAX_SIZE);\n    stack->size = 0;\n    return stack;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayStack(ArrayStack *stack) {\n    free(stack->data);\n    free(stack);\n}\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(ArrayStack *stack) {\n    return stack->size;\n}\n\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(ArrayStack *stack) {\n    return stack->size == 0;\n}\n\n/* \u5165\u6808 */\nvoid push(ArrayStack *stack, int num) {\n    if (stack->size == MAX_SIZE) {\n        printf(\"\u6808\u5df2\u6ee1\\n\");\n        return;\n    }\n    stack->data[stack->size] = num;\n    stack->size++;\n}\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(ArrayStack *stack) {\n    if (stack->size == 0) {\n        printf(\"\u6808\u4e3a\u7a7a\\n\");\n        return INT_MAX;\n    }\n    return stack->data[stack->size - 1];\n}\n\n/* \u51fa\u6808 */\nint pop(ArrayStack *stack) {\n    int val = peek(stack);\n    stack->size--;\n    return val;\n}\n
    array_stack.zig
    // \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\nfn ArrayStack(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        stack: ?std.ArrayList(T) = null,     \n\n        // \u6784\u9020\u65b9\u6cd5\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) void {\n            if (self.stack == null) {\n                self.stack = std.ArrayList(T).init(allocator);\n            }\n        }\n\n        // \u6790\u6784\u65b9\u6cd5\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.stack == null) return;\n            self.stack.?.deinit();\n        }\n\n        // \u83b7\u53d6\u6808\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.stack.?.items.len;\n        }\n\n        // \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u8bbf\u95ee\u6808\u9876\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u6808\u4e3a\u7a7a\");\n            return self.stack.?.items[self.size() - 1];\n        }  \n\n        // \u5165\u6808\n        pub fn push(self: *Self, num: T) !void {\n            try self.stack.?.append(num);\n        } \n\n        // \u51fa\u6808\n        pub fn pop(self: *Self) T {\n            var num = self.stack.?.pop();\n            return num;\n        } \n\n        // \u8fd4\u56de ArrayList\n        pub fn toList(self: *Self) std.ArrayList(T) {\n            return 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\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 None \u3002\u7531\u4e8e\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5e76\u4e0d\u5305\u542b\u8fd9\u4e9b None \uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u6cd5\u4ec5\u51ed\u8be5\u5e8f\u5217\u6765\u63a8\u6d4b 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 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\uff0cNone \u53ea\u51fa\u73b0\u5728\u6700\u5e95\u5c42\u4e14\u9760\u53f3\u7684\u4f4d\u7f6e\uff0c\u56e0\u6b64\u6240\u6709 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 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\"\"\"\n\n    def __init__(self, arr: list[int | None]):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._tree = list(arr)\n\n    def size(self):\n        \"\"\"\u8282\u70b9\u6570\u91cf\"\"\"\n        return len(self._tree)\n\n    def 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\n        if i < 0 or i >= self.size():\n            return None\n        return self._tree[i]\n\n    def left(self, i: int) -> int | None:\n        \"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n        return 2 * i + 1\n\n    def right(self, i: int) -> int | None:\n        \"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n        return 2 * i + 2\n\n    def parent(self, i: int) -> int | None:\n        \"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n        return (i - 1) // 2\n\n    def level_order(self) -> list[int]:\n        \"\"\"\u5c42\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        # \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for i in range(self.size()):\n            if self.val(i) is not None:\n                self.res.append(self.val(i))\n        return self.res\n\n    def dfs(self, i: int, order: str):\n        \"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386\"\"\"\n        if self.val(i) is None:\n            return\n        # \u524d\u5e8f\u904d\u5386\n        if order == \"pre\":\n            self.res.append(self.val(i))\n        self.dfs(self.left(i), order)\n        # \u4e2d\u5e8f\u904d\u5386\n        if order == \"in\":\n            self.res.append(self.val(i))\n        self.dfs(self.right(i), order)\n        # \u540e\u5e8f\u904d\u5386\n        if order == \"post\":\n            self.res.append(self.val(i))\n\n    def pre_order(self) -> list[int]:\n        \"\"\"\u524d\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        self.dfs(0, order=\"pre\")\n        return self.res\n\n    def in_order(self) -> list[int]:\n        \"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        self.dfs(0, order=\"in\")\n        return self.res\n\n    def post_order(self) -> list[int]:\n        \"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        self.dfs(0, order=\"post\")\n        return self.res\n
    array_binary_tree.cpp
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    ArrayBinaryTree(vector<int> arr) {\n        tree = arr;\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    int size() {\n        return tree.size();\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    int val(int i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de INT_MAX \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= size())\n            return INT_MAX;\n        return tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    int left(int i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    int right(int i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    int parent(int i) {\n        return (i - 1) / 2;\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    vector<int> levelOrder() {\n        vector<int> res;\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (int i = 0; i < size(); i++) {\n            if (val(i) != INT_MAX)\n                res.push_back(val(i));\n        }\n        return res;\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    vector<int> preOrder() {\n        vector<int> res;\n        dfs(0, \"pre\", res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    vector<int> inOrder() {\n        vector<int> res;\n        dfs(0, \"in\", res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    vector<int> postOrder() {\n        vector<int> res;\n        dfs(0, \"post\", res);\n        return res;\n    }\n\n  private:\n    vector<int> tree;\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    void dfs(int i, string order, vector<int> &res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (val(i) == INT_MAX)\n            return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order == \"pre\")\n            res.push_back(val(i));\n        dfs(left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order == \"in\")\n            res.push_back(val(i));\n        dfs(right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order == \"post\")\n            res.push_back(val(i));\n    }\n};\n
    array_binary_tree.java
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n    private List<Integer> tree;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public ArrayBinaryTree(List<Integer> arr) {\n        tree = new ArrayList<>(arr);\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    public int size() {\n        return tree.size();\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    public Integer val(int i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= size())\n            return null;\n        return tree.get(i);\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public Integer left(int i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public Integer right(int i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    public Integer parent(int i) {\n        return (i - 1) / 2;\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    public List<Integer> levelOrder() {\n        List<Integer> res = new ArrayList<>();\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (int i = 0; i < size(); i++) {\n            if (val(i) != null)\n                res.add(val(i));\n        }\n        return res;\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    private void dfs(Integer i, String order, List<Integer> res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (val(i) == null)\n            return;\n        // \u524d\u5e8f\u904d\u5386\n        if (\"pre\".equals(order))\n            res.add(val(i));\n        dfs(left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (\"in\".equals(order))\n            res.add(val(i));\n        dfs(right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (\"post\".equals(order))\n            res.add(val(i));\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    public List<Integer> preOrder() {\n        List<Integer> res = new ArrayList<>();\n        dfs(0, \"pre\", res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    public List<Integer> inOrder() {\n        List<Integer> res = new ArrayList<>();\n        dfs(0, \"in\", res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    public List<Integer> postOrder() {\n        List<Integer> res = new ArrayList<>();\n        dfs(0, \"post\", res);\n        return res;\n    }\n}\n
    array_binary_tree.cs
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree(List<int?> arr) {\n    List<int?> tree = new(arr);\n\n    /* \u8282\u70b9\u6570\u91cf */\n    public int Size() {\n        return tree.Count;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    public int? Val(int i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= Size())\n            return null;\n        return tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public int Left(int i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public int Right(int i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    public int Parent(int i) {\n        return (i - 1) / 2;\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    public List<int> LevelOrder() {\n        List<int> res = [];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (int i = 0; i < Size(); i++) {\n            if (Val(i).HasValue)\n                res.Add(Val(i)!.Value);\n        }\n        return res;\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    void DFS(int i, string order, List<int> res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (!Val(i).HasValue)\n            return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order == \"pre\")\n            res.Add(Val(i)!.Value);\n        DFS(Left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order == \"in\")\n            res.Add(Val(i)!.Value);\n        DFS(Right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order == \"post\")\n            res.Add(Val(i)!.Value);\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    public List<int> PreOrder() {\n        List<int> res = [];\n        DFS(0, \"pre\", res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    public List<int> InOrder() {\n        List<int> res = [];\n        DFS(0, \"in\", res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    public List<int> PostOrder() {\n        List<int> res = [];\n        DFS(0, \"post\", res);\n        return res;\n    }\n}\n
    array_binary_tree.go
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\ntype arrayBinaryTree struct {\n    tree []any\n}\n\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newArrayBinaryTree(arr []any) *arrayBinaryTree {\n    return &arrayBinaryTree{\n        tree: arr,\n    }\n}\n\n/* \u8282\u70b9\u6570\u91cf */\nfunc (abt *arrayBinaryTree) size() int {\n    return len(abt.tree)\n}\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\n    if i < 0 || i >= abt.size() {\n        return nil\n    }\n    return abt.tree[i]\n}\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 {\n    return 2*i + 1\n}\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 {\n    return 2*i + 2\n}\n\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) parent(i int) int {\n    return (i - 1) / 2\n}\n\n/* \u5c42\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) levelOrder() []any {\n    var res []any\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n    for i := 0; i < abt.size(); i++ {\n        if abt.val(i) != nil {\n            res = append(res, abt.val(i))\n        }\n    }\n    return res\n}\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\n    if abt.val(i) == nil {\n        return\n    }\n    // \u524d\u5e8f\u904d\u5386\n    if order == \"pre\" {\n        *res = append(*res, abt.val(i))\n    }\n    abt.dfs(abt.left(i), order, res)\n    // \u4e2d\u5e8f\u904d\u5386\n    if order == \"in\" {\n        *res = append(*res, abt.val(i))\n    }\n    abt.dfs(abt.right(i), order, res)\n    // \u540e\u5e8f\u904d\u5386\n    if order == \"post\" {\n        *res = append(*res, abt.val(i))\n    }\n}\n\n/* \u524d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) preOrder() []any {\n    var res []any\n    abt.dfs(0, \"pre\", &res)\n    return res\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) inOrder() []any {\n    var res []any\n    abt.dfs(0, \"in\", &res)\n    return res\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) postOrder() []any {\n    var res []any\n    abt.dfs(0, \"post\", &res)\n    return res\n}\n
    array_binary_tree.swift
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n    private var tree: [Int?]\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init(arr: [Int?]) {\n        tree = arr\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    func size() -> Int {\n        tree.count\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    func val(i: Int) -> Int? {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if i < 0 || i >= size() {\n            return nil\n        }\n        return tree[i]\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    func left(i: Int) -> Int {\n        2 * i + 1\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    func right(i: Int) -> Int {\n        2 * i + 2\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    func parent(i: Int) -> Int {\n        (i - 1) / 2\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    func levelOrder() -> [Int] {\n        var res: [Int] = []\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for i in stride(from: 0, to: size(), by: 1) {\n            if let val = val(i: i) {\n                res.append(val)\n            }\n        }\n        return res\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    private func dfs(i: Int, order: String, res: inout [Int]) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        guard let val = val(i: i) else {\n            return\n        }\n        // \u524d\u5e8f\u904d\u5386\n        if order == \"pre\" {\n            res.append(val)\n        }\n        dfs(i: left(i: i), order: order, res: &res)\n        // \u4e2d\u5e8f\u904d\u5386\n        if order == \"in\" {\n            res.append(val)\n        }\n        dfs(i: right(i: i), order: order, res: &res)\n        // \u540e\u5e8f\u904d\u5386\n        if order == \"post\" {\n            res.append(val)\n        }\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    func preOrder() -> [Int] {\n        var res: [Int] = []\n        dfs(i: 0, order: \"pre\", res: &res)\n        return res\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    func inOrder() -> [Int] {\n        var res: [Int] = []\n        dfs(i: 0, order: \"in\", res: &res)\n        return res\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    func postOrder() -> [Int] {\n        var res: [Int] = []\n        dfs(i: 0, order: \"post\", res: &res)\n        return res\n    }\n}\n
    array_binary_tree.js
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n    #tree;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(arr) {\n        this.#tree = arr;\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    size() {\n        return this.#tree.length;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    val(i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= this.size()) return null;\n        return this.#tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    left(i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    right(i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    parent(i) {\n        return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    levelOrder() {\n        let res = [];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (let i = 0; i < this.size(); i++) {\n            if (this.val(i) !== null) res.push(this.val(i));\n        }\n        return res;\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    #dfs(i, order, res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (this.val(i) === null) return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order === 'pre') res.push(this.val(i));\n        this.#dfs(this.left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order === 'in') res.push(this.val(i));\n        this.#dfs(this.right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order === 'post') res.push(this.val(i));\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    preOrder() {\n        const res = [];\n        this.#dfs(0, 'pre', res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    inOrder() {\n        const res = [];\n        this.#dfs(0, 'in', res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    postOrder() {\n        const res = [];\n        this.#dfs(0, 'post', res);\n        return 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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(arr: (number | null)[]) {\n        this.#tree = arr;\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    size(): number {\n        return this.#tree.length;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    val(i: number): number | null {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= this.size()) return null;\n        return this.#tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    left(i: number): number {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    right(i: number): number {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    parent(i: number): number {\n        return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    levelOrder(): number[] {\n        let res = [];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (let i = 0; i < this.size(); i++) {\n            if (this.val(i) !== null) res.push(this.val(i));\n        }\n        return res;\n    }\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\n        if (this.val(i) === null) return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order === 'pre') res.push(this.val(i));\n        this.#dfs(this.left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order === 'in') res.push(this.val(i));\n        this.#dfs(this.right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order === 'post') res.push(this.val(i));\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    preOrder(): (number | null)[] {\n        const res = [];\n        this.#dfs(0, 'pre', res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    inOrder(): (number | null)[] {\n        const res = [];\n        this.#dfs(0, 'in', res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    postOrder(): (number | null)[] {\n        const res = [];\n        this.#dfs(0, 'post', res);\n        return res;\n    }\n}\n
    array_binary_tree.dart
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n  late List<int?> _tree;\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  ArrayBinaryTree(this._tree);\n\n  /* \u8282\u70b9\u6570\u91cf */\n  int size() {\n    return _tree.length;\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n  int? val(int i) {\n    // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n    if (i < 0 || i >= size()) {\n      return null;\n    }\n    return _tree[i];\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n  int? left(int i) {\n    return 2 * i + 1;\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n  int? right(int i) {\n    return 2 * i + 2;\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n  int? parent(int i) {\n    return (i - 1) ~/ 2;\n  }\n\n  /* \u5c42\u5e8f\u904d\u5386 */\n  List<int> levelOrder() {\n    List<int> res = [];\n    for (int i = 0; i < size(); i++) {\n      if (val(i) != null) {\n        res.add(val(i)!);\n      }\n    }\n    return res;\n  }\n\n  /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n  void dfs(int i, String order, List<int?> res) {\n    // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n    if (val(i) == null) {\n      return;\n    }\n    // \u524d\u5e8f\u904d\u5386\n    if (order == 'pre') {\n      res.add(val(i));\n    }\n    dfs(left(i)!, order, res);\n    // \u4e2d\u5e8f\u904d\u5386\n    if (order == 'in') {\n      res.add(val(i));\n    }\n    dfs(right(i)!, order, res);\n    // \u540e\u5e8f\u904d\u5386\n    if (order == 'post') {\n      res.add(val(i));\n    }\n  }\n\n  /* \u524d\u5e8f\u904d\u5386 */\n  List<int?> preOrder() {\n    List<int?> res = [];\n    dfs(0, 'pre', res);\n    return res;\n  }\n\n  /* \u4e2d\u5e8f\u904d\u5386 */\n  List<int?> inOrder() {\n    List<int?> res = [];\n    dfs(0, 'in', res);\n    return res;\n  }\n\n  /* \u540e\u5e8f\u904d\u5386 */\n  List<int?> postOrder() {\n    List<int?> res = [];\n    dfs(0, 'post', res);\n    return res;\n  }\n}\n
    array_binary_tree.rs
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nstruct ArrayBinaryTree {\n    tree: Vec<Option<i32>>,\n}\n\nimpl ArrayBinaryTree {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(arr: Vec<Option<i32>>) -> Self {\n        Self { tree: arr }\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    fn size(&self) -> i32 {\n        self.tree.len() as i32\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    fn val(&self, i: i32) -> Option<i32> {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de None \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if i < 0 || i >= self.size() {\n            None\n        } else {\n            self.tree[i as usize]\n        }\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    fn left(&self, i: i32) -> i32 {\n        2 * i + 1\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    fn right(&self, i: i32) -> i32 {\n        2 * i + 2\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    fn parent(&self, i: i32) -> i32 {\n        (i - 1) / 2\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    fn level_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for i in 0..self.size() {\n            if let Some(val) = self.val(i) {\n                res.push(val)\n            }\n        }\n        res\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    fn dfs(&self, i: i32, order: &str, res: &mut Vec<i32>) {\n        if self.val(i).is_none() {\n            return;\n        }\n        let val = self.val(i).unwrap();\n        // \u524d\u5e8f\u904d\u5386\n        if order == \"pre\" {\n            res.push(val);\n        }\n        self.dfs(self.left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if order == \"in\" {\n            res.push(val);\n        }\n        self.dfs(self.right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if order == \"post\" {\n            res.push(val);\n        }\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    fn pre_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        self.dfs(0, \"pre\", &mut res);\n        res\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    fn in_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        self.dfs(0, \"in\", &mut res);\n        res\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    fn post_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        self.dfs(0, \"post\", &mut res);\n        res\n    }\n}\n
    array_binary_tree.c
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7ed3\u6784\u4f53 */\ntypedef struct {\n    int *tree;\n    int size;\n} ArrayBinaryTree;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayBinaryTree *newArrayBinaryTree(int *arr, int arrSize) {\n    ArrayBinaryTree *abt = (ArrayBinaryTree *)malloc(sizeof(ArrayBinaryTree));\n    abt->tree = malloc(sizeof(int) * arrSize);\n    memcpy(abt->tree, arr, sizeof(int) * arrSize);\n    abt->size = arrSize;\n    return abt;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayBinaryTree(ArrayBinaryTree *abt) {\n    free(abt->tree);\n    free(abt);\n}\n\n/* \u8282\u70b9\u6570\u91cf */\nint size(ArrayBinaryTree *abt) {\n    return abt->size;\n}\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\n    if (i < 0 || i >= size(abt))\n        return INT_MAX;\n    return abt->tree[i];\n}\n\n/* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < size(abt); i++) {\n        if (val(abt, i) != INT_MAX)\n            res[index++] = val(abt, i);\n    }\n    *returnSize = index;\n    return res;\n}\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\n    if (val(abt, i) == INT_MAX)\n        return;\n    // \u524d\u5e8f\u904d\u5386\n    if (strcmp(order, \"pre\") == 0)\n        res[(*index)++] = val(abt, i);\n    dfs(abt, left(i), order, res, index);\n    // \u4e2d\u5e8f\u904d\u5386\n    if (strcmp(order, \"in\") == 0)\n        res[(*index)++] = val(abt, i);\n    dfs(abt, right(i), order, res, index);\n    // \u540e\u5e8f\u904d\u5386\n    if (strcmp(order, \"post\") == 0)\n        res[(*index)++] = val(abt, i);\n}\n\n/* \u524d\u5e8f\u904d\u5386 */\nint *preOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    dfs(abt, 0, \"pre\", res, &index);\n    *returnSize = index;\n    return res;\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nint *inOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    dfs(abt, 0, \"in\", res, &index);\n    *returnSize = index;\n    return res;\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nint *postOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    dfs(abt, 0, \"post\", res, &index);\n    *returnSize = index;\n    return 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 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\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)\\) \u52a3\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\u52a3\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\u201cAn algorithm for the organization of information\u201d\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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val                 # \u8282\u70b9\u503c\n        self.height: int = 0                # \u8282\u70b9\u9ad8\u5ea6\n        self.left: TreeNode | None = None   # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n        self.right: TreeNode | None = None  # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nstruct TreeNode {\n    int val{};          // \u8282\u70b9\u503c\n    int height = 0;     // \u8282\u70b9\u9ad8\u5ea6\n    TreeNode *left{};   // \u5de6\u5b50\u8282\u70b9\n    TreeNode *right{};  // \u53f3\u5b50\u8282\u70b9\n    TreeNode() = default;\n    explicit TreeNode(int x) : val(x){}\n};\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    public int val;        // \u8282\u70b9\u503c\n    public int height;     // \u8282\u70b9\u9ad8\u5ea6\n    public TreeNode left;  // \u5de6\u5b50\u8282\u70b9\n    public TreeNode right; // \u53f3\u5b50\u8282\u70b9\n    public TreeNode(int x) { val = x; }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\n    public int? val = x;    // \u8282\u70b9\u503c\n    public int height;      // \u8282\u70b9\u9ad8\u5ea6\n    public TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    public TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
    /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\n    Val    int       // \u8282\u70b9\u503c\n    Height int       // \u8282\u70b9\u9ad8\u5ea6\n    Left   *TreeNode // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    Right  *TreeNode // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    var val: Int // \u8282\u70b9\u503c\n    var height: Int // \u8282\u70b9\u9ad8\u5ea6\n    var left: TreeNode? // \u5de6\u5b50\u8282\u70b9\n    var right: TreeNode? // \u53f3\u5b50\u8282\u70b9\n\n    init(x: Int) {\n        val = x\n        height = 0\n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val; // \u8282\u70b9\u503c\n    height; //\u8282\u70b9\u9ad8\u5ea6\n    left; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    constructor(val, left, right, height) {\n        this.val = val === undefined ? 0 : val;\n        this.height = height === undefined ? 0 : height;\n        this.left = left === undefined ? null : left;\n        this.right = right === undefined ? null : right;\n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val: number;            // \u8282\u70b9\u503c\n    height: number;         // \u8282\u70b9\u9ad8\u5ea6\n    left: TreeNode | null;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    right: TreeNode | null; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    constructor(val?: number, height?: number, left?: TreeNode | null, right?: TreeNode | null) {\n        this.val = val === undefined ? 0 : val;\n        this.height = height === undefined ? 0 : height; \n        this.left = left === undefined ? null : left; \n        this.right = right === undefined ? null : right; \n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n  int val;         // \u8282\u70b9\u503c\n  int height;      // \u8282\u70b9\u9ad8\u5ea6\n  TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\n  TreeNode? right; // \u53f3\u5b50\u8282\u70b9\n  TreeNode(this.val, [this.height = 0, this.left, this.right]);\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\n    val: i32,                               // \u8282\u70b9\u503c\n    height: i32,                            // \u8282\u70b9\u9ad8\u5ea6\n    left: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\n    right: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\n}\n\nimpl TreeNode {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(val: i32) -> Rc<RefCell<Self>> {\n        Rc::new(RefCell::new(Self {\n            val,\n            height: 0,\n            left: None,\n            right: None\n        }))\n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nTreeNode struct TreeNode {\n    int val;\n    int height;\n    struct TreeNode *left;\n    struct TreeNode *right;\n} TreeNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\n    TreeNode *node;\n\n    node = (TreeNode *)malloc(sizeof(TreeNode));\n    node->val = val;\n    node->height = 0;\n    node->left = NULL;\n    node->right = NULL;\n    return node;\n}\n
    \n

    \u201c\u8282\u70b9\u9ad8\u5ea6\u201d\u662f\u6307\u4ece\u8be5\u8282\u70b9\u5230\u5b83\u7684\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\n    if node is not None:\n        return node.height\n    return -1\n\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\n    node.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\n    return node == nullptr ? -1 : node->height;\n}\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\n    node->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\n    return node == null ? -1 : node.height;\n}\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\n    node.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\n    return node == null ? -1 : node.height;\n}\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\n    node.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\n    if node != nil {\n        return node.Height\n    }\n    return -1\n}\n\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfunc (t *aVLTree) updateHeight(node *TreeNode) {\n    lh := t.height(node.Left)\n    rh := t.height(node.Right)\n    // \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\n    if lh > rh {\n        node.Height = lh + 1\n    } else {\n        node.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\n    node == nil ? -1 : node!.height\n}\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\n    node?.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\n    return node === null ? -1 : node.height;\n}\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\n    node.height =\n        Math.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\n    return node === null ? -1 : node.height;\n}\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\n    node.height =\n        Math.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\n  return node == null ? -1 : node.height;\n}\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\n  node!.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\n    match node {\n        Some(node) => node.borrow().height,\n        None => -1,\n    }\n}\n\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfn update_height(node: OptionTreeNodeRc) {\n    if let Some(node) = node {\n        let left = node.borrow().left.clone();\n        let right = node.borrow().right.clone();\n        // \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\n        node.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\n    if (node != NULL) {\n        return node->height;\n    }\n    return -1;\n}\n\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode *node) {\n    int lh = height(node->left);\n    int rh = height(node->right);\n    // \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\n    if (lh > rh) {\n        node->height = lh + 1;\n    } else {\n        node->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\n    return if (node == null) -1 else node.?.height;\n}\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\n    node.?.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\n    if node is None:\n        return 0\n    # \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == nullptr)\n        return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == null)\n        return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if node == nil {\n        return 0\n    }\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    guard let node = node else { return 0 }\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node === null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node === null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n  if (node == null) return 0;\n  // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n  return height(node.left) - height(node.right);\n}\n
    avl_tree.rs
    /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfn balance_factor(node: OptionTreeNodeRc) -> i32 {\n    match node {\n        // \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\n        None => 0,\n        // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n        Some(node) => {\n            Self::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\n    if (node == NULL) {\n        return 0;\n    }\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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 grand_child \uff09\u65f6\uff0c\u9700\u8981\u5728\u53f3\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grand_child \u4f5c\u4e3a node \u7684\u5de6\u5b50\u8282\u70b9\u3002

    \u56fe 7-27 \u00a0 \u6709 grand_child \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\"\"\"\n    child = node.left\n    grand_child = child.right\n    # \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node\n    node.left = grand_child\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    self.update_height(child)\n    # \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n
    avl_tree.cpp
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\n    TreeNode *child = node->left;\n    TreeNode *grandChild = child->right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child->right = node;\n    node->left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.java
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode rightRotate(TreeNode node) {\n    TreeNode child = node.left;\n    TreeNode grandChild = child.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.cs
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? RightRotate(TreeNode? node) {\n    TreeNode? child = node?.left;\n    TreeNode? grandChild = child?.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    UpdateHeight(node);\n    UpdateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.go
    /* \u53f3\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) rightRotate(node *TreeNode) *TreeNode {\n    child := node.Left\n    grandChild := child.Right\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.Right = node\n    node.Left = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    t.updateHeight(child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.swift
    /* \u53f3\u65cb\u64cd\u4f5c */\nfunc rightRotate(node: TreeNode?) -> TreeNode? {\n    let child = node?.left\n    let grandChild = child?.right\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child?.right = node\n    node?.left = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node: node)\n    updateHeight(node: child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.js
    /* \u53f3\u65cb\u64cd\u4f5c */\n#rightRotate(node) {\n    const child = node.left;\n    const grandChild = child.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.#updateHeight(node);\n    this.#updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.ts
    /* \u53f3\u65cb\u64cd\u4f5c */\nrightRotate(node: TreeNode): TreeNode {\n    const child = node.left;\n    const grandChild = child.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.updateHeight(node);\n    this.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.dart
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? rightRotate(TreeNode? node) {\n  TreeNode? child = node!.left;\n  TreeNode? grandChild = child!.right;\n  // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n  child.right = node;\n  node.left = grandChild;\n  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n  updateHeight(node);\n  updateHeight(child);\n  // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return child;\n}\n
    avl_tree.rs
    /* \u53f3\u65cb\u64cd\u4f5c */\nfn right_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\n    match node {\n        Some(node) => {\n            let child = node.borrow().left.clone().unwrap();\n            let grand_child = child.borrow().right.clone();\n            // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n            child.borrow_mut().right = Some(node.clone());\n            node.borrow_mut().left = grand_child;\n            // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n            Self::update_height(Some(node));\n            Self::update_height(Some(child.clone()));\n            // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(child)\n        }\n        None => None,\n    }\n}\n
    avl_tree.c
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\n    TreeNode *child, *grandChild;\n    child = node->left;\n    grandChild = child->right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child->right = node;\n    node->left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.zig
    // \u53f3\u65cb\u64cd\u4f5c\nfn rightRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\n    var child = node.?.left;\n    var grandChild = child.?.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.?.right = node;\n    node.?.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.updateHeight(node);\n    self.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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 grand_child \uff09\u65f6\uff0c\u9700\u8981\u5728\u5de6\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grand_child \u4f5c\u4e3a node \u7684\u53f3\u5b50\u8282\u70b9\u3002

    \u56fe 7-29 \u00a0 \u6709 grand_child \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\"\"\"\n    child = node.right\n    grand_child = child.left\n    # \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node\n    node.right = grand_child\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    self.update_height(child)\n    # \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n
    avl_tree.cpp
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\n    TreeNode *child = node->right;\n    TreeNode *grandChild = child->left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child->left = node;\n    node->right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.java
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode leftRotate(TreeNode node) {\n    TreeNode child = node.right;\n    TreeNode grandChild = child.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.cs
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? LeftRotate(TreeNode? node) {\n    TreeNode? child = node?.right;\n    TreeNode? grandChild = child?.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    UpdateHeight(node);\n    UpdateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.go
    /* \u5de6\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) leftRotate(node *TreeNode) *TreeNode {\n    child := node.Right\n    grandChild := child.Left\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.Left = node\n    node.Right = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    t.updateHeight(child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.swift
    /* \u5de6\u65cb\u64cd\u4f5c */\nfunc leftRotate(node: TreeNode?) -> TreeNode? {\n    let child = node?.right\n    let grandChild = child?.left\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child?.left = node\n    node?.right = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node: node)\n    updateHeight(node: child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.js
    /* \u5de6\u65cb\u64cd\u4f5c */\n#leftRotate(node) {\n    const child = node.right;\n    const grandChild = child.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.#updateHeight(node);\n    this.#updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.ts
    /* \u5de6\u65cb\u64cd\u4f5c */\nleftRotate(node: TreeNode): TreeNode {\n    const child = node.right;\n    const grandChild = child.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.updateHeight(node);\n    this.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.dart
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? leftRotate(TreeNode? node) {\n  TreeNode? child = node!.right;\n  TreeNode? grandChild = child!.left;\n  // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n  child.left = node;\n  node.right = grandChild;\n  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n  updateHeight(node);\n  updateHeight(child);\n  // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return child;\n}\n
    avl_tree.rs
    /* \u5de6\u65cb\u64cd\u4f5c */\nfn left_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\n    match node {\n        Some(node) => {\n            let child = node.borrow().right.clone().unwrap();\n            let grand_child = child.borrow().left.clone();\n            // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n            child.borrow_mut().left = Some(node.clone());\n            node.borrow_mut().right = grand_child;\n            // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n            Self::update_height(Some(node));\n            Self::update_height(Some(child.clone()));\n            // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(child)\n        }\n        None => None,\n    }\n}\n
    avl_tree.c
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\n    TreeNode *child, *grandChild;\n    child = node->right;\n    grandChild = child->left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child->left = node;\n    node->right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.zig
    // \u5de6\u65cb\u64cd\u4f5c\nfn leftRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\n    var child = node.?.right;\n    var grandChild = child.?.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.?.left = node;\n    node.?.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.updateHeight(node);\n    self.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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\n    balance_factor = self.balance_factor(node)\n    # \u5de6\u504f\u6811\n    if balance_factor > 1:\n        if self.balance_factor(node.left) >= 0:\n            # \u53f3\u65cb\n            return self.right_rotate(node)\n        else:\n            # \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = self.left_rotate(node.left)\n            return self.right_rotate(node)\n    # \u53f3\u504f\u6811\n    elif balance_factor < -1:\n        if self.balance_factor(node.right) <= 0:\n            # \u5de6\u65cb\n            return self.left_rotate(node)\n        else:\n            # \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = self.right_rotate(node.right)\n            return self.left_rotate(node)\n    # \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    int _balanceFactor = balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (_balanceFactor > 1) {\n        if (balanceFactor(node->left) >= 0) {\n            // \u53f3\u65cb\n            return rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node->left = leftRotate(node->left);\n            return rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (_balanceFactor < -1) {\n        if (balanceFactor(node->right) <= 0) {\n            // \u5de6\u65cb\n            return leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node->right = rightRotate(node->right);\n            return leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    int balanceFactor = balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactor > 1) {\n        if (balanceFactor(node.left) >= 0) {\n            // \u53f3\u65cb\n            return rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = leftRotate(node.left);\n            return rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactor < -1) {\n        if (balanceFactor(node.right) <= 0) {\n            // \u5de6\u65cb\n            return leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = rightRotate(node.right);\n            return leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    int balanceFactorInt = BalanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactorInt > 1) {\n        if (BalanceFactor(node?.left) >= 0) {\n            // \u53f3\u65cb\n            return RightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node!.left = LeftRotate(node!.left);\n            return RightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactorInt < -1) {\n        if (BalanceFactor(node?.right) <= 0) {\n            // \u5de6\u65cb\n            return LeftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node!.right = RightRotate(node!.right);\n            return LeftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    bf := t.balanceFactor(node)\n    // \u5de6\u504f\u6811\n    if bf > 1 {\n        if t.balanceFactor(node.Left) >= 0 {\n            // \u53f3\u65cb\n            return t.rightRotate(node)\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.Left = t.leftRotate(node.Left)\n            return t.rightRotate(node)\n        }\n    }\n    // \u53f3\u504f\u6811\n    if bf < -1 {\n        if t.balanceFactor(node.Right) <= 0 {\n            // \u5de6\u65cb\n            return t.leftRotate(node)\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.Right = t.rightRotate(node.Right)\n            return t.leftRotate(node)\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    let balanceFactor = balanceFactor(node: node)\n    // \u5de6\u504f\u6811\n    if balanceFactor > 1 {\n        if self.balanceFactor(node: node?.left) >= 0 {\n            // \u53f3\u65cb\n            return rightRotate(node: node)\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node?.left = leftRotate(node: node?.left)\n            return rightRotate(node: node)\n        }\n    }\n    // \u53f3\u504f\u6811\n    if balanceFactor < -1 {\n        if self.balanceFactor(node: node?.right) <= 0 {\n            // \u5de6\u65cb\n            return leftRotate(node: node)\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node?.right = rightRotate(node: node?.right)\n            return leftRotate(node: node)\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    const balanceFactor = this.balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactor > 1) {\n        if (this.balanceFactor(node.left) >= 0) {\n            // \u53f3\u65cb\n            return this.#rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = this.#leftRotate(node.left);\n            return this.#rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactor < -1) {\n        if (this.balanceFactor(node.right) <= 0) {\n            // \u5de6\u65cb\n            return this.#leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = this.#rightRotate(node.right);\n            return this.#leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    const balanceFactor = this.balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactor > 1) {\n        if (this.balanceFactor(node.left) >= 0) {\n            // \u53f3\u65cb\n            return this.rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = this.leftRotate(node.left);\n            return this.rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactor < -1) {\n        if (this.balanceFactor(node.right) <= 0) {\n            // \u5de6\u65cb\n            return this.leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = this.rightRotate(node.right);\n            return this.leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n  int factor = balanceFactor(node);\n  // \u5de6\u504f\u6811\n  if (factor > 1) {\n    if (balanceFactor(node!.left) >= 0) {\n      // \u53f3\u65cb\n      return rightRotate(node);\n    } else {\n      // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n      node.left = leftRotate(node.left);\n      return rightRotate(node);\n    }\n  }\n  // \u53f3\u504f\u6811\n  if (factor < -1) {\n    if (balanceFactor(node!.right) <= 0) {\n      // \u5de6\u65cb\n      return leftRotate(node);\n    } else {\n      // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n      node.right = rightRotate(node.right);\n      return leftRotate(node);\n    }\n  }\n  // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n  return 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\n    let balance_factor = Self::balance_factor(node.clone());\n    // \u5de6\u504f\u6811\n    if balance_factor > 1 {\n        let node = node.unwrap();\n        if Self::balance_factor(node.borrow().left.clone()) >= 0 {\n            // \u53f3\u65cb\n            Self::right_rotate(Some(node))\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            let left = node.borrow().left.clone();\n            node.borrow_mut().left = Self::left_rotate(left);\n            Self::right_rotate(Some(node))\n        }\n    }\n    // \u53f3\u504f\u6811\n    else if balance_factor < -1 {\n        let node = node.unwrap();\n        if Self::balance_factor(node.borrow().right.clone()) <= 0 {\n            // \u5de6\u65cb\n            Self::left_rotate(Some(node))\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            let right = node.borrow().right.clone();\n            node.borrow_mut().right = Self::right_rotate(right);\n            Self::left_rotate(Some(node))\n        }\n    } else {\n        // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n        node\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\n    int bf = balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (bf > 1) {\n        if (balanceFactor(node->left) >= 0) {\n            // \u53f3\u65cb\n            return rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node->left = leftRotate(node->left);\n            return rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (bf < -1) {\n        if (balanceFactor(node->right) <= 0) {\n            // \u5de6\u65cb\n            return leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node->right = rightRotate(node->right);\n            return leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    var balance_factor = self.balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balance_factor > 1) {\n        if (self.balanceFactor(node.?.left) >= 0) {\n            // \u53f3\u65cb\n            return self.rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.?.left = self.leftRotate(node.?.left);\n            return self.rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balance_factor < -1) {\n        if (self.balanceFactor(node.?.right) <= 0) {\n            // \u5de6\u65cb\n            return self.leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.?.right = self.rightRotate(node.?.right);\n            return self.leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\"\"\"\n    self._root = self.insert_helper(self._root, val)\n\ndef insert_helper(self, node: TreeNode | None, val: int) -> TreeNode:\n    \"\"\"\u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\n    if node is None:\n        return TreeNode(val)\n    # 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9\n    if val < node.val:\n        node.left = self.insert_helper(node.left, val)\n    elif val > node.val:\n        node.right = self.insert_helper(node.right, val)\n    else:\n        # \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n        return node\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    # 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\n    return self.rotate(node)\n
    avl_tree.cpp
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\n    root = insertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\n    if (node == nullptr)\n        return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node->val)\n        node->left = insertHelper(node->left, val);\n    else if (val > node->val)\n        node->right = insertHelper(node->right, val);\n    else\n        return node;    // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.java
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\n    root = insertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode insertHelper(TreeNode node, int val) {\n    if (node == null)\n        return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val)\n        node.left = insertHelper(node.left, val);\n    else if (val > node.val)\n        node.right = insertHelper(node.right, val);\n    else\n        return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.cs
    /* \u63d2\u5165\u8282\u70b9 */\nvoid Insert(int val) {\n    root = InsertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? InsertHelper(TreeNode? node, int val) {\n    if (node == null) return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val)\n        node.left = InsertHelper(node.left, val);\n    else if (val > node.val)\n        node.right = InsertHelper(node.right, val);\n    else\n        return node;     // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    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 */\n    node = Rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.go
    /* \u63d2\u5165\u8282\u70b9 */\nfunc (t *aVLTree) insert(val int) {\n    t.root = t.insertHelper(t.root, val)\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) insertHelper(node *TreeNode, val int) *TreeNode {\n    if node == nil {\n        return NewTreeNode(val)\n    }\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if val < node.Val.(int) {\n        node.Left = t.insertHelper(node.Left, val)\n    } else if val > node.Val.(int) {\n        node.Right = t.insertHelper(node.Right, val)\n    } else {\n        // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n        return node\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = t.rotate(node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.swift
    /* \u63d2\u5165\u8282\u70b9 */\nfunc insert(val: Int) {\n    root = insertHelper(node: root, val: val)\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc insertHelper(node: TreeNode?, val: Int) -> TreeNode? {\n    var node = node\n    if node == nil {\n        return TreeNode(x: val)\n    }\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if val < node!.val {\n        node?.left = insertHelper(node: node?.left, val: val)\n    } else if val > node!.val {\n        node?.right = insertHelper(node: node?.right, val: val)\n    } else {\n        return node // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    }\n    updateHeight(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 */\n    node = rotate(node: node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.js
    /* \u63d2\u5165\u8282\u70b9 */\ninsert(val) {\n    this.root = this.#insertHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#insertHelper(node, val) {\n    if (node === null) return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val) node.left = this.#insertHelper(node.left, val);\n    else if (val > node.val)\n        node.right = this.#insertHelper(node.right, val);\n    else return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    this.#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 */\n    node = this.#rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.ts
    /* \u63d2\u5165\u8282\u70b9 */\ninsert(val: number): void {\n    this.root = this.insertHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\ninsertHelper(node: TreeNode, val: number): TreeNode {\n    if (node === null) return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val) {\n        node.left = this.insertHelper(node.left, val);\n    } else if (val > node.val) {\n        node.right = this.insertHelper(node.right, val);\n    } else {\n        return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    }\n    this.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 */\n    node = this.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.dart
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\n  root = insertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? insertHelper(TreeNode? node, int val) {\n  if (node == null) return TreeNode(val);\n  /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n  if (val < node.val)\n    node.left = insertHelper(node.left, val);\n  else if (val > node.val)\n    node.right = insertHelper(node.right, val);\n  else\n    return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n  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 */\n  node = rotate(node);\n  // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return node;\n}\n
    avl_tree.rs
    /* \u63d2\u5165\u8282\u70b9 */\nfn insert(&mut self, val: i32) {\n    self.root = Self::insert_helper(self.root.clone(), val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn insert_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\n    match node {\n        Some(mut node) => {\n            /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n            match {\n                let node_val = node.borrow().val;\n                node_val\n            }\n            .cmp(&val)\n            {\n                Ordering::Greater => {\n                    let left = node.borrow().left.clone();\n                    node.borrow_mut().left = Self::insert_helper(left, val);\n                }\n                Ordering::Less => {\n                    let right = node.borrow().right.clone();\n                    node.borrow_mut().right = Self::insert_helper(right, val);\n                }\n                Ordering::Equal => {\n                    return Some(node); // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n                }\n            }\n            Self::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 */\n            node = Self::rotate(Some(node)).unwrap();\n            // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(node)\n        }\n        None => Some(TreeNode::new(val)),\n    }\n}\n
    avl_tree.c
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(AVLTree *tree, int val) {\n    tree->root = insertHelper(tree->root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\n    if (node == NULL) {\n        return newTreeNode(val);\n    }\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node->val) {\n        node->left = insertHelper(node->left, val);\n    } else if (val > node->val) {\n        node->right = insertHelper(node->right, val);\n    } else {\n        // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n        return node;\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.zig
    // \u63d2\u5165\u8282\u70b9\nfn insert(self: *Self, val: T) !void {\n    self.root = (try self.insertHelper(self.root, val)).?;\n}\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) {\n    var node = node_;\n    if (node == null) {\n        var tmp_node = try self.mem_allocator.create(inc.TreeNode(T));\n        tmp_node.init(val);\n        return tmp_node;\n    }\n    // 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9\n    if (val < node.?.val) {\n        node.?.left = try self.insertHelper(node.?.left, val);\n    } else if (val > node.?.val) {\n        node.?.right = try self.insertHelper(node.?.right, val);\n    } else {\n        return node;            // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    }\n    self.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\n    node = self.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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\"\"\"\n    self._root = self.remove_helper(self._root, val)\n\ndef remove_helper(self, node: TreeNode | None, val: int) -> TreeNode | None:\n    \"\"\"\u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\n    if node is None:\n        return None\n    # 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664\n    if val < node.val:\n        node.left = self.remove_helper(node.left, val)\n    elif val > node.val:\n        node.right = self.remove_helper(node.right, val)\n    else:\n        if node.left is None or node.right is None:\n            child = node.left or node.right\n            # \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if child is None:\n                return None\n            # \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else:\n                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\n            temp = node.right\n            while temp.left is not None:\n                temp = temp.left\n            node.right = self.remove_helper(node.right, temp.val)\n            node.val = temp.val\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    # 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\n    return self.rotate(node)\n
    avl_tree.cpp
    /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\n    root = removeHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\n    if (node == nullptr)\n        return nullptr;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node->val)\n        node->left = removeHelper(node->left, val);\n    else if (val > node->val)\n        node->right = removeHelper(node->right, val);\n    else {\n        if (node->left == nullptr || node->right == nullptr) {\n            TreeNode *child = node->left != nullptr ? node->left : node->right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == nullptr) {\n                delete node;\n                return nullptr;\n            }\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else {\n                delete node;\n                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\n            TreeNode *temp = node->right;\n            while (temp->left != nullptr) {\n                temp = temp->left;\n            }\n            int tempVal = temp->val;\n            node->right = removeHelper(node->right, temp->val);\n            node->val = tempVal;\n        }\n    }\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.java
    /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\n    root = removeHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode removeHelper(TreeNode node, int val) {\n    if (node == null)\n        return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val)\n        node.left = removeHelper(node.left, val);\n    else if (val > node.val)\n        node.right = removeHelper(node.right, val);\n    else {\n        if (node.left == null || node.right == null) {\n            TreeNode child = node.left != null ? node.left : node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == null)\n                return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else\n                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\n            TreeNode temp = node.right;\n            while (temp.left != null) {\n                temp = temp.left;\n            }\n            node.right = removeHelper(node.right, temp.val);\n            node.val = temp.val;\n        }\n    }\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.cs
    /* \u5220\u9664\u8282\u70b9 */\nvoid Remove(int val) {\n    root = RemoveHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? RemoveHelper(TreeNode? node, int val) {\n    if (node == null) return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val)\n        node.left = RemoveHelper(node.left, val);\n    else if (val > node.val)\n        node.right = RemoveHelper(node.right, val);\n    else {\n        if (node.left == null || node.right == null) {\n            TreeNode? child = node.left ?? node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == null)\n                return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else\n                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\n            TreeNode? temp = node.right;\n            while (temp.left != null) {\n                temp = temp.left;\n            }\n            node.right = RemoveHelper(node.right, temp.val!.Value);\n            node.val = temp.val;\n        }\n    }\n    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 */\n    node = Rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.go
    /* \u5220\u9664\u8282\u70b9 */\nfunc (t *aVLTree) remove(val int) {\n    t.root = t.removeHelper(t.root, val)\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) removeHelper(node *TreeNode, val int) *TreeNode {\n    if node == nil {\n        return nil\n    }\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if val < node.Val.(int) {\n        node.Left = t.removeHelper(node.Left, val)\n    } else if val > node.Val.(int) {\n        node.Right = t.removeHelper(node.Right, val)\n    } else {\n        if node.Left == nil || node.Right == nil {\n            child := node.Left\n            if node.Right != nil {\n                child = node.Right\n            }\n            if child == nil {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n                return nil\n            } else {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                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\n            temp := node.Right\n            for temp.Left != nil {\n                temp = temp.Left\n            }\n            node.Right = t.removeHelper(node.Right, temp.Val.(int))\n            node.Val = temp.Val\n        }\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = t.rotate(node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.swift
    /* \u5220\u9664\u8282\u70b9 */\nfunc remove(val: Int) {\n    root = removeHelper(node: root, val: val)\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc removeHelper(node: TreeNode?, val: Int) -> TreeNode? {\n    var node = node\n    if node == nil {\n        return nil\n    }\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if val < node!.val {\n        node?.left = removeHelper(node: node?.left, val: val)\n    } else if val > node!.val {\n        node?.right = removeHelper(node: node?.right, val: val)\n    } else {\n        if node?.left == nil || node?.right == nil {\n            let child = node?.left != nil ? node?.left : node?.right\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if child == nil {\n                return nil\n            }\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else {\n                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\n            var temp = node?.right\n            while temp?.left != nil {\n                temp = temp?.left\n            }\n            node?.right = removeHelper(node: node?.right, val: temp!.val)\n            node?.val = temp!.val\n        }\n    }\n    updateHeight(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 */\n    node = rotate(node: node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.js
    /* \u5220\u9664\u8282\u70b9 */\nremove(val) {\n    this.root = this.#removeHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#removeHelper(node, val) {\n    if (node === null) return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val) node.left = this.#removeHelper(node.left, val);\n    else if (val > node.val)\n        node.right = this.#removeHelper(node.right, val);\n    else {\n        if (node.left === null || node.right === null) {\n            const child = node.left !== null ? node.left : node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child === null) return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else 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\n            let temp = node.right;\n            while (temp.left !== null) {\n                temp = temp.left;\n            }\n            node.right = this.#removeHelper(node.right, temp.val);\n            node.val = temp.val;\n        }\n    }\n    this.#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 */\n    node = this.#rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.ts
    /* \u5220\u9664\u8282\u70b9 */\nremove(val: number): void {\n    this.root = this.removeHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nremoveHelper(node: TreeNode, val: number): TreeNode {\n    if (node === null) return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val) {\n        node.left = this.removeHelper(node.left, val);\n    } else if (val > node.val) {\n        node.right = this.removeHelper(node.right, val);\n    } else {\n        if (node.left === null || node.right === null) {\n            const child = node.left !== null ? node.left : node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child === null) {\n                return null;\n            } else {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                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\n            let temp = node.right;\n            while (temp.left !== null) {\n                temp = temp.left;\n            }\n            node.right = this.removeHelper(node.right, temp.val);\n            node.val = temp.val;\n        }\n    }\n    this.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 */\n    node = this.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.dart
    /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\n  root = removeHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? removeHelper(TreeNode? node, int val) {\n  if (node == null) return null;\n  /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n  if (val < node.val)\n    node.left = removeHelper(node.left, val);\n  else if (val > node.val)\n    node.right = removeHelper(node.right, val);\n  else {\n    if (node.left == null || node.right == null) {\n      TreeNode? child = node.left ?? node.right;\n      // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n      if (child == null)\n        return null;\n      // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n      else\n        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\n      TreeNode? temp = node.right;\n      while (temp!.left != null) {\n        temp = temp.left;\n      }\n      node.right = removeHelper(node.right, temp.val);\n      node.val = temp.val;\n    }\n  }\n  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 */\n  node = rotate(node);\n  // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return node;\n}\n
    avl_tree.rs
    /* \u5220\u9664\u8282\u70b9 */\nfn remove(&self, val: i32) {\n    Self::remove_helper(self.root.clone(), val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn remove_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\n    match node {\n        Some(mut node) => {\n            /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n            if val < node.borrow().val {\n                let left = node.borrow().left.clone();\n                node.borrow_mut().left = Self::remove_helper(left, val);\n            } else if val > node.borrow().val {\n                let right = node.borrow().right.clone();\n                node.borrow_mut().right = Self::remove_helper(right, val);\n            } else if node.borrow().left.is_none() || node.borrow().right.is_none() {\n                let child = if node.borrow().left.is_some() {\n                    node.borrow().left.clone()\n                } else {\n                    node.borrow().right.clone()\n                };\n                match child {\n                    // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n                    None => {\n                        return None;\n                    }\n                    // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                    Some(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\n                let mut temp = node.borrow().right.clone().unwrap();\n                loop {\n                    let temp_left = temp.borrow().left.clone();\n                    if temp_left.is_none() {\n                        break;\n                    }\n                    temp = temp_left.unwrap();\n                }\n                let right = node.borrow().right.clone();\n                node.borrow_mut().right = Self::remove_helper(right, temp.borrow().val);\n                node.borrow_mut().val = temp.borrow().val;\n            }\n            Self::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 */\n            node = Self::rotate(Some(node)).unwrap();\n            // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(node)\n        }\n        None => 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) {\n    TreeNode *root = removeHelper(tree->root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\n    TreeNode *child, *grandChild;\n    if (node == NULL) {\n        return NULL;\n    }\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node->val) {\n        node->left = removeHelper(node->left, val);\n    } else if (val > node->val) {\n        node->right = removeHelper(node->right, val);\n    } else {\n        if (node->left == NULL || node->right == NULL) {\n            child = node->left;\n            if (node->right != NULL) {\n                child = node->right;\n            }\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == NULL) {\n                return NULL;\n            } else {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                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\n            TreeNode *temp = node->right;\n            while (temp->left != NULL) {\n                temp = temp->left;\n            }\n            int tempVal = temp->val;\n            node->right = removeHelper(node->right, temp->val);\n            node->val = tempVal;\n        }\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.zig
    // \u5220\u9664\u8282\u70b9\nfn remove(self: *Self, val: T) void {\n   self.root = self.removeHelper(self.root, val).?;\n}\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) {\n    var node = node_;\n    if (node == null) return null;\n    // 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664\n    if (val < node.?.val) {\n        node.?.left = self.removeHelper(node.?.left, val);\n    } else if (val > node.?.val) {\n        node.?.right = self.removeHelper(node.?.right, val);\n    } else {\n        if (node.?.left == null or node.?.right == null) {\n            var 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\n            if (child == null) {\n                return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            } else {\n                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\n            var temp = node.?.right;\n            while (temp.?.left != null) {\n                temp = temp.?.left;\n            }\n            node.?.right = self.removeHelper(node.?.right, temp.?.val);\n            node.?.val = temp.?.val;\n        }\n    }\n    self.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\n    node = self.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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\"\"\"\n    cur = self._root\n    # \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur is not None:\n        # \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur.val < num:\n            cur = cur.right\n        # \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        elif cur.val > num:\n            cur = cur.left\n        # \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else:\n            break\n    return cur\n
    binary_search_tree.cpp
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(int num) {\n    TreeNode *cur = root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != nullptr) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur->val < num)\n            cur = cur->right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur->val > num)\n            cur = cur->left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else\n            break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.java
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode search(int num) {\n    TreeNode cur = root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num)\n            cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else\n            break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.cs
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? Search(int num) {\n    TreeNode? cur = root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur =\n            cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num)\n            cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else\n            break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.go
    /* \u67e5\u627e\u8282\u70b9 */\nfunc (bst *binarySearchTree) search(num int) *TreeNode {\n    node := bst.root\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    for node != nil {\n        if node.Val.(int) < num {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            node = node.Right\n        } else if node.Val.(int) > num {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            node = node.Left\n        } else {\n            // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            break\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return node\n}\n
    binary_search_tree.swift
    /* \u67e5\u627e\u8282\u70b9 */\nfunc search(num: Int) -> TreeNode? {\n    var cur = root\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur != nil {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur!.val < num {\n            cur = cur?.right\n        }\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if cur!.val > num {\n            cur = cur?.left\n        }\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else {\n            break\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur\n}\n
    binary_search_tree.js
    /* \u67e5\u627e\u8282\u70b9 */\nsearch(num) {\n    let cur = this.root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num) cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.ts
    /* \u67e5\u627e\u8282\u70b9 */\nsearch(num: number): TreeNode | null {\n    let cur = this.root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num) cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.dart
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? search(int _num) {\n  TreeNode? cur = _root;\n  // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n  while (cur != null) {\n    // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n    if (cur.val < _num)\n      cur = cur.right;\n    // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n    else if (cur.val > _num)\n      cur = cur.left;\n    // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n    else\n      break;\n  }\n  // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n  return cur;\n}\n
    binary_search_tree.rs
    /* \u67e5\u627e\u8282\u70b9 */\npub fn search(&self, num: i32) -> OptionTreeNodeRc {\n    let mut cur = self.root.clone();\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while let Some(node) = cur.clone() {\n        match num.cmp(&node.borrow().val) {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            Ordering::Greater => cur = node.borrow().right.clone(),\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            Ordering::Less => cur = node.borrow().left.clone(),\n            // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            Ordering::Equal => break,\n        }\n    }\n\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    cur\n}\n
    binary_search_tree.c
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(BinarySearchTree *bst, int num) {\n    TreeNode *cur = bst->root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != NULL) {\n        if (cur->val < num) {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            cur = cur->right;\n        } else if (cur->val > num) {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            cur = cur->left;\n        } else {\n            // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.zig
    // \u67e5\u627e\u8282\u70b9\nfn search(self: *Self, num: T) ?*inc.TreeNode(T) {\n    var cur = self.root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.?.val < num) {\n            cur = cur.?.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        } else if (cur.?.val > num) {\n            cur = cur.?.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        } else {\n            break;\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return 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 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 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 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\n    if self._root is None:\n        self._root = TreeNode(num)\n        return\n    # \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    cur, pre = self._root, None\n    while cur is not None:\n        # \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if cur.val == num:\n            return\n        pre = cur\n        # \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur.val < num:\n            cur = cur.right\n        # \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else:\n            cur = cur.left\n    # \u63d2\u5165\u8282\u70b9\n    node = TreeNode(num)\n    if pre.val < num:\n        pre.right = node\n    else:\n        pre.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\n    if (root == nullptr) {\n        root = new TreeNode(num);\n        return;\n    }\n    TreeNode *cur = root, *pre = nullptr;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != nullptr) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur->val == num)\n            return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur->val < num)\n            cur = cur->right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur->left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode *node = new TreeNode(num);\n    if (pre->val < num)\n        pre->right = node;\n    else\n        pre->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\n    if (root == null) {\n        root = new TreeNode(num);\n        return;\n    }\n    TreeNode cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val == num)\n            return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode node = new TreeNode(num);\n    if (pre.val < num)\n        pre.right = node;\n    else\n        pre.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\n    if (root == null) {\n        root = new TreeNode(num);\n        return;\n    }\n    TreeNode? cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val == num)\n            return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode node = new(num);\n    if (pre != null) {\n        if (pre.val < num)\n            pre.right = node;\n        else\n            pre.left = node;\n    }\n}\n
    binary_search_tree.go
    /* \u63d2\u5165\u8282\u70b9 */\nfunc (bst *binarySearchTree) insert(num int) {\n    cur := bst.root\n    // \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\n    if cur == nil {\n        bst.root = NewTreeNode(num)\n        return\n    }\n    // \u5f85\u63d2\u5165\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\n    var pre *TreeNode = nil\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    for cur != nil {\n        if cur.Val == num {\n            return\n        }\n        pre = cur\n        if cur.Val.(int) < num {\n            cur = cur.Right\n        } else {\n            cur = cur.Left\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    node := NewTreeNode(num)\n    if pre.Val.(int) < num {\n        pre.Right = node\n    } else {\n        pre.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\n    if root == nil {\n        root = TreeNode(x: num)\n        return\n    }\n    var cur = root\n    var pre: TreeNode?\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur != nil {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if cur!.val == num {\n            return\n        }\n        pre = cur\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur!.val < num {\n            cur = cur?.right\n        }\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else {\n            cur = cur?.left\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    let node = TreeNode(x: num)\n    if pre!.val < num {\n        pre?.right = node\n    } else {\n        pre?.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\n    if (this.root === null) {\n        this.root = new TreeNode(num);\n        return;\n    }\n    let cur = this.root,\n        pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val === num) return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    const node = new TreeNode(num);\n    if (pre.val < num) pre.right = node;\n    else 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\n    if (this.root === null) {\n        this.root = new TreeNode(num);\n        return;\n    }\n    let cur: TreeNode | null = this.root,\n        pre: TreeNode | null = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val === num) return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    const node = new TreeNode(num);\n    if (pre!.val < num) pre!.right = node;\n    else 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\n  if (_root == null) {\n    _root = TreeNode(_num);\n    return;\n  }\n  TreeNode? cur = _root;\n  TreeNode? pre = null;\n  // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n  while (cur != null) {\n    // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n    if (cur.val == _num) return;\n    pre = cur;\n    // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n    if (cur.val < _num)\n      cur = cur.right;\n    // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n    else\n      cur = cur.left;\n  }\n  // \u63d2\u5165\u8282\u70b9\n  TreeNode? node = TreeNode(_num);\n  if (pre!.val < _num)\n    pre.right = node;\n  else\n    pre.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\n    if self.root.is_none() {\n        self.root = Some(TreeNode::new(num));\n        return;\n    }\n    let mut cur = self.root.clone();\n    let mut pre = None;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while let Some(node) = cur.clone() {\n        match num.cmp(&node.borrow().val) {\n            // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n            Ordering::Equal => return,\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            Ordering::Greater => {\n                pre = cur.clone();\n                cur = node.borrow().right.clone();\n            }\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            Ordering::Less => {\n                pre = cur.clone();\n                cur = node.borrow().left.clone();\n            }\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    let pre = pre.unwrap();\n    let node = Some(TreeNode::new(num));\n    if num > pre.borrow().val {\n        pre.borrow_mut().right = node;\n    } else {\n        pre.borrow_mut().left = 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\n    if (bst->root == NULL) {\n        bst->root = newTreeNode(num);\n        return;\n    }\n    TreeNode *cur = bst->root, *pre = NULL;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != NULL) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur->val == num) {\n            return;\n        }\n        pre = cur;\n        if (cur->val < num) {\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            cur = cur->right;\n        } else {\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            cur = cur->left;\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode *node = newTreeNode(num);\n    if (pre->val < num) {\n        pre->right = node;\n    } else {\n        pre->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\n    if (self.root == null) {\n        self.root = try self.mem_allocator.create(inc.TreeNode(T));\n        return;\n    }\n    var cur = self.root;\n    var pre: ?*inc.TreeNode(T) = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.?.val == num) return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.?.val < num) {\n            cur = cur.?.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        } else {\n            cur = cur.?.left;\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    var node = try self.mem_allocator.create(inc.TreeNode(T));\n    node.init(num);\n    if (pre.?.val < num) {\n        pre.?.right = node;\n    } else {\n        pre.?.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\n    if self._root is None:\n        return\n    # \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    cur, pre = self._root, None\n    while cur is not None:\n        # \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if cur.val == num:\n            break\n        pre = cur\n        # \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur.val < num:\n            cur = cur.right\n        # \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else:\n            cur = cur.left\n    # \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur is None:\n        return\n\n    # \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if 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\n        child = cur.left or cur.right\n        # \u5220\u9664\u8282\u70b9 cur\n        if cur != self._root:\n            if pre.left == cur:\n                pre.left = child\n            else:\n                pre.right = child\n        else:\n            # \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            self._root = child\n    # \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else:\n        # \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        tmp: TreeNode = cur.right\n        while tmp.left is not None:\n            tmp = tmp.left\n        # \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        self.remove(tmp.val)\n        # \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if (root == nullptr)\n        return;\n    TreeNode *cur = root, *pre = nullptr;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != nullptr) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur->val == num)\n            break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur->val < num)\n            cur = cur->right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur->left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == nullptr)\n        return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur->left == nullptr || cur->right == nullptr) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\n        TreeNode *child = cur->left != nullptr ? cur->left : cur->right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur != root) {\n            if (pre->left == cur)\n                pre->left = child;\n            else\n                pre->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        // \u91ca\u653e\u5185\u5b58\n        delete cur;\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\n        TreeNode *tmp = cur->right;\n        while (tmp->left != nullptr) {\n            tmp = tmp->left;\n        }\n        int tmpVal = tmp->val;\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        remove(tmp->val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur->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\n    if (root == null)\n        return;\n    TreeNode cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val == num)\n            break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == null)\n        return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left == null || cur.right == null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        TreeNode child = cur.left != null ? cur.left : cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur != root) {\n            if (pre.left == cur)\n                pre.left = child;\n            else\n                pre.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    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else {\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        TreeNode tmp = cur.right;\n        while (tmp.left != null) {\n            tmp = tmp.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        remove(tmp.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if (root == null)\n        return;\n    TreeNode? cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val == num)\n            break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == null)\n        return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left == null || cur.right == null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        TreeNode? child = cur.left ?? cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur != root) {\n            if (pre!.left == cur)\n                pre.left = child;\n            else\n                pre.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    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else {\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        TreeNode? tmp = cur.right;\n        while (tmp.left != null) {\n            tmp = tmp.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        Remove(tmp.val!.Value);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.val = tmp.val;\n    }\n}\n
    binary_search_tree.go
    /* \u5220\u9664\u8282\u70b9 */\nfunc (bst *binarySearchTree) remove(num int) {\n    cur := bst.root\n    // \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\n    if cur == nil {\n        return\n    }\n    // \u5f85\u5220\u9664\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\n    var pre *TreeNode = nil\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    for cur != nil {\n        if cur.Val == num {\n            break\n        }\n        pre = cur\n        if cur.Val.(int) < num {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728\u53f3\u5b50\u6811\u4e2d\n            cur = cur.Right\n        } else {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728\u5de6\u5b50\u6811\u4e2d\n            cur = cur.Left\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur == nil {\n        return\n    }\n    // \u5b50\u8282\u70b9\u6570\u4e3a 0 \u6216 1\n    if cur.Left == nil || cur.Right == nil {\n        var child *TreeNode = nil\n        // \u53d6\u51fa\u5f85\u5220\u9664\u8282\u70b9\u7684\u5b50\u8282\u70b9\n        if cur.Left != nil {\n            child = cur.Left\n        } else {\n            child = cur.Right\n        }\n        // \u5220\u9664\u8282\u70b9 cur\n        if cur != bst.root {\n            if pre.Left == cur {\n                pre.Left = child\n            } else {\n                pre.Right = child\n            }\n        } else {\n            // \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            bst.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\n        tmp := cur.Right\n        for tmp.Left != nil {\n            tmp = tmp.Left\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        bst.remove(tmp.Val.(int))\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if root == nil {\n        return\n    }\n    var cur = root\n    var pre: TreeNode?\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur != nil {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if cur!.val == num {\n            break\n        }\n        pre = cur\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur!.val < num {\n            cur = cur?.right\n        }\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else {\n            cur = cur?.left\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur == nil {\n        return\n    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if cur?.left == nil || cur?.right == nil {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        let child = cur?.left != nil ? cur?.left : cur?.right\n        // \u5220\u9664\u8282\u70b9 cur\n        if cur !== root {\n            if pre?.left === cur {\n                pre?.left = child\n            } else {\n                pre?.right = child\n            }\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    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else {\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        var tmp = cur?.right\n        while tmp?.left != nil {\n            tmp = tmp?.left\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        remove(num: tmp!.val)\n        // \u7528 tmp \u8986\u76d6 cur\n        cur?.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\n    if (this.root === null) return;\n    let cur = this.root,\n        pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val === num) break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur === null) return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left === null || cur.right === null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        const child = cur.left !== null ? cur.left : cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur !== this.root) {\n            if (pre.left === cur) pre.left = child;\n            else pre.right = child;\n        } else {\n            // \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            this.root = child;\n        }\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\n        let tmp = cur.right;\n        while (tmp.left !== null) {\n            tmp = tmp.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        this.remove(tmp.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if (this.root === null) return;\n    let cur: TreeNode | null = this.root,\n        pre: TreeNode | null = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val === num) break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur === null) return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left === null || cur.right === null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        const child: TreeNode | null =\n            cur.left !== null ? cur.left : cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur !== this.root) {\n            if (pre!.left === cur) pre!.left = child;\n            else pre!.right = child;\n        } else {\n            // \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            this.root = child;\n        }\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\n        let tmp: TreeNode | null = cur.right;\n        while (tmp!.left !== null) {\n            tmp = tmp!.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        this.remove(tmp!.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n  if (_root == null) return;\n  TreeNode? cur = _root;\n  TreeNode? pre = null;\n  // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n  while (cur != null) {\n    // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n    if (cur.val == _num) break;\n    pre = cur;\n    // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n    if (cur.val < _num)\n      cur = cur.right;\n    // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n    else\n      cur = cur.left;\n  }\n  // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n  if (cur == null) return;\n  // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n  if (cur.left == null || cur.right == null) {\n    // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n    TreeNode? child = cur.left ?? cur.right;\n    // \u5220\u9664\u8282\u70b9 cur\n    if (cur != _root) {\n      if (pre!.left == cur)\n        pre.left = child;\n      else\n        pre.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\n    TreeNode? tmp = cur.right;\n    while (tmp!.left != null) {\n      tmp = tmp.left;\n    }\n    // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n    remove(tmp.val);\n    // \u7528 tmp \u8986\u76d6 cur\n    cur.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\n    if self.root.is_none() { \n        return; \n    }\n    let mut cur = self.root.clone();\n    let mut pre = None;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while let Some(node) = cur.clone() {\n        match num.cmp(&node.borrow().val) {\n            // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            Ordering::Equal => break,\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            Ordering::Greater => {\n                pre = cur.clone();\n                cur = node.borrow().right.clone();\n            }\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            Ordering::Less => {\n                pre = cur.clone();\n                cur = node.borrow().left.clone();\n            }\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur.is_none() {\n        return;\n    }\n    let cur = cur.unwrap();\n    let (left_child, right_child) = (cur.borrow().left.clone(), cur.borrow().right.clone());\n    match (left_child.clone(), right_child.clone()) {\n        // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n        (None, None) | (Some(_), None) | (None, Some(_)) => {\n            // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\n            let child = left_child.or(right_child);\n            let pre = pre.unwrap();\n            // \u5220\u9664\u8282\u70b9 cur\n            if !Rc::ptr_eq(&cur, self.root.as_ref().unwrap()) {\n                let left = pre.borrow().left.clone();\n                if left.is_some() && Rc::ptr_eq(&left.as_ref().unwrap(), &cur) {\n                    pre.borrow_mut().left = child;\n                } else {\n                    pre.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\n                self.root = child;\n            }\n        }\n        // \u5b50\u8282\u70b9\u6570\u91cf = 2\n        (Some(_), Some(_)) => {\n            // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n            let mut tmp = cur.borrow().right.clone();\n            while let Some(node) = tmp.clone() {\n                if node.borrow().left.is_some() {\n                    tmp = node.borrow().left.clone();\n                } else {\n                    break;\n                }\n            }\n            let tmpval = tmp.unwrap().borrow().val;\n            // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n            self.remove(tmpval);\n            // \u7528 tmp \u8986\u76d6 cur\n            cur.borrow_mut().val = tmpval;\n        }\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\n    if (bst->root == NULL)\n        return;\n    TreeNode *cur = bst->root, *pre = NULL;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != NULL) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur->val == num)\n            break;\n        pre = cur;\n        if (cur->val < num) {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u53f3\u5b50\u6811\u4e2d\n            cur = cur->right;\n        } else {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u5de6\u5b50\u6811\u4e2d\n            cur = cur->left;\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == NULL)\n        return;\n    // \u5224\u65ad\u5f85\u5220\u9664\u8282\u70b9\u662f\u5426\u5b58\u5728\u5b50\u8282\u70b9\n    if (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\n        TreeNode *child = cur->left != NULL ? cur->left : cur->right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (pre->left == cur) {\n            pre->left = child;\n        } else {\n            pre->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\n        TreeNode *tmp = cur->right;\n        while (tmp->left != NULL) {\n            tmp = tmp->left;\n        }\n        int tmpVal = tmp->val;\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        removeItem(bst, tmp->val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur->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\n    if (self.root == null) return;\n    var cur = self.root;\n    var pre: ?*inc.TreeNode(T) = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.?.val == num) break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.?.val < num) {\n            cur = cur.?.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        } else {\n            cur = cur.?.left;\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == null) return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.?.left == null or cur.?.right == null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        var child = if (cur.?.left != null) cur.?.left else cur.?.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (pre.?.left == cur) {\n            pre.?.left = child;\n        } else {\n            pre.?.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\n        var tmp = cur.?.right;\n        while (tmp.?.left != null) {\n            tmp = tmp.?.left;\n        }\n        var tmp_val = tmp.?.val;\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        self.remove(tmp.?.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.?.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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val                # \u8282\u70b9\u503c\n        self.left: TreeNode | None = None  # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n        self.right: TreeNode | None = None # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\n    int val;          // \u8282\u70b9\u503c\n    TreeNode *left;   // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    TreeNode *right;  // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n};\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    int val;         // \u8282\u70b9\u503c\n    TreeNode left;   // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    TreeNode right;  // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n    TreeNode(int x) { val = x; }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\n    public int? val = x;    // \u8282\u70b9\u503c\n    public TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    public TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\n    Val   int\n    Left  *TreeNode\n    Right *TreeNode\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc NewTreeNode(v int) *TreeNode {\n    return &TreeNode{\n        Left:  nil, // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n        Right: nil, // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n        Val:   v,   // \u8282\u70b9\u503c\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    var val: Int // \u8282\u70b9\u503c\n    var left: TreeNode? // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    var right: TreeNode? // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n\n    init(x: Int) {\n        val = x\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val; // \u8282\u70b9\u503c\n    left; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    constructor(val, left, right) {\n        this.val = val === undefined ? 0 : val;\n        this.left = left === undefined ? null : left;\n        this.right = right === undefined ? null : right;\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val: number;\n    left: TreeNode | null;\n    right: TreeNode | null;\n\n    constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n        this.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\n        this.left = left === undefined ? null : left; // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n        this.right = right === undefined ? null : right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n  int val;         // \u8282\u70b9\u503c\n  TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n  TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n  TreeNode(this.val, [this.left, this.right]);\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\n    val: i32,                               // \u8282\u70b9\u503c\n    left: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    right: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n\nimpl TreeNode {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(val: i32) -> Rc<RefCell<Self>> {\n        Rc::new(RefCell::new(Self {\n            val,\n            left: None,\n            right: None\n        }))\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct TreeNode {\n    int val;                // \u8282\u70b9\u503c\n    int height;             // \u8282\u70b9\u9ad8\u5ea6\n    struct TreeNode *left;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    struct TreeNode *right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n} TreeNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\n    TreeNode *node;\n\n    node = (TreeNode *)malloc(sizeof(TreeNode));\n    node->val = val;\n    node->height = 0;\n    node->left = NULL;\n    node->right = NULL;\n    return 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 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),\n    n2 = new TreeNode(2),\n    n3 = new TreeNode(3),\n    n4 = new TreeNode(4),\n    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.ts
    /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = new TreeNode(1),\n    n2 = new TreeNode(2),\n    n3 = new TreeNode(3),\n    n4 = new TreeNode(4),\n    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.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\u300d\uff0c\u4e5f\u79f0\u300c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22 breadth-first search, 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\n    queue: deque[TreeNode] = deque()\n    queue.append(root)\n    # \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    res = []\n    while queue:\n        node: TreeNode = queue.popleft()  # \u961f\u5217\u51fa\u961f\n        res.append(node.val)  # \u4fdd\u5b58\u8282\u70b9\u503c\n        if node.left is not None:\n            queue.append(node.left)  # \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if node.right is not None:\n            queue.append(node.right)  # \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    return 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\n    queue<TreeNode *> queue;\n    queue.push(root);\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    vector<int> vec;\n    while (!queue.empty()) {\n        TreeNode *node = queue.front();\n        queue.pop();              // \u961f\u5217\u51fa\u961f\n        vec.push_back(node->val); // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node->left != nullptr)\n            queue.push(node->left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node->right != nullptr)\n            queue.push(node->right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    Queue<TreeNode> queue = new LinkedList<>();\n    queue.add(root);\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    List<Integer> list = new ArrayList<>();\n    while (!queue.isEmpty()) {\n        TreeNode node = queue.poll(); // \u961f\u5217\u51fa\u961f\n        list.add(node.val);           // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left != null)\n            queue.offer(node.left);   // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node.right != null)\n            queue.offer(node.right);  // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    Queue<TreeNode> queue = new();\n    queue.Enqueue(root);\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    List<int> list = [];\n    while (queue.Count != 0) {\n        TreeNode node = queue.Dequeue(); // \u961f\u5217\u51fa\u961f\n        list.Add(node.val!.Value);       // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left != null)\n            queue.Enqueue(node.left);    // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node.right != null)\n            queue.Enqueue(node.right);   // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    queue := list.New()\n    queue.PushBack(root)\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5207\u7247\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    nums := make([]any, 0)\n    for queue.Len() > 0 {\n        // \u961f\u5217\u51fa\u961f\n        node := queue.Remove(queue.Front()).(*TreeNode)\n        // \u4fdd\u5b58\u8282\u70b9\u503c\n        nums = append(nums, node.Val)\n        if node.Left != nil {\n            // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n            queue.PushBack(node.Left)\n        }\n        if node.Right != nil {\n            // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n            queue.PushBack(node.Right)\n        }\n    }\n    return 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\n    var queue: [TreeNode] = [root]\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    var list: [Int] = []\n    while !queue.isEmpty {\n        let node = queue.removeFirst() // \u961f\u5217\u51fa\u961f\n        list.append(node.val) // \u4fdd\u5b58\u8282\u70b9\u503c\n        if let left = node.left {\n            queue.append(left) // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if let right = node.right {\n            queue.append(right) // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        }\n    }\n    return 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\n    const queue = [root];\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    const list = [];\n    while (queue.length) {\n        let node = queue.shift(); // \u961f\u5217\u51fa\u961f\n        list.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left) queue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node.right) queue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    const queue = [root];\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    const list: number[] = [];\n    while (queue.length) {\n        let node = queue.shift() as TreeNode; // \u961f\u5217\u51fa\u961f\n        list.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left) {\n            queue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if (node.right) {\n            queue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        }\n    }\n    return 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\n  Queue<TreeNode?> queue = Queue();\n  queue.add(root);\n  // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n  List<int> res = [];\n  while (queue.isNotEmpty) {\n    TreeNode? node = queue.removeFirst(); // \u961f\u5217\u51fa\u961f\n    res.add(node!.val); // \u4fdd\u5b58\u8282\u70b9\u503c\n    if (node.left != null) queue.add(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n    if (node.right != null) queue.add(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n  }\n  return 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\n    let mut que = VecDeque::new();\n    que.push_back(Rc::clone(&root));\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    let mut vec = Vec::new();\n\n    while let Some(node) = que.pop_front() {                 // \u961f\u5217\u51fa\u961f\n        vec.push(node.borrow().val);                         // \u4fdd\u5b58\u8282\u70b9\u503c\n        if let Some(left) = node.borrow().left.as_ref() {\n            que.push_back(Rc::clone(left));                  // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if let Some(right) = node.borrow().right.as_ref() {\n            que.push_back(Rc::clone(right));                 // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        };\n    }\n    vec\n}\n
    binary_tree_bfs.c
    /* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(TreeNode *root, int *size) {\n    /* \u8f85\u52a9\u961f\u5217 */\n    int front, rear;\n    int index, *arr;\n    TreeNode *node;\n    TreeNode **queue;\n\n    /* \u8f85\u52a9\u961f\u5217 */\n    queue = (TreeNode **)malloc(sizeof(TreeNode *) * MAX_SIZE);\n    // \u961f\u5217\u6307\u9488\n    front = 0, rear = 0;\n    // \u52a0\u5165\u6839\u8282\u70b9\n    queue[rear++] = root;\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    /* \u8f85\u52a9\u6570\u7ec4 */\n    arr = (int *)malloc(sizeof(int) * MAX_SIZE);\n    // \u6570\u7ec4\u6307\u9488\n    index = 0;\n    while (front < rear) {\n        // \u961f\u5217\u51fa\u961f\n        node = queue[front++];\n        // \u4fdd\u5b58\u8282\u70b9\u503c\n        arr[index++] = node->val;\n        if (node->left != NULL) {\n            // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n            queue[rear++] = node->left;\n        }\n        if (node->right != NULL) {\n            // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n            queue[rear++] = node->right;\n        }\n    }\n    // \u66f4\u65b0\u6570\u7ec4\u957f\u5ea6\u7684\u503c\n    *size = index;\n    arr = realloc(arr, sizeof(int) * (*size));\n\n    // \u91ca\u653e\u8f85\u52a9\u6570\u7ec4\u7a7a\u95f4\n    free(queue);\n    return 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\n    const L = std.TailQueue(*inc.TreeNode(T));\n    var queue = L{};\n    var root_node = try mem_allocator.create(L.Node);\n    root_node.data = root;\n    queue.append(root_node); \n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    var list = std.ArrayList(T).init(std.heap.page_allocator);\n    while (queue.len > 0) {\n        var queue_node = queue.popFirst().?;    // \u961f\u5217\u51fa\u961f\n        var node = queue_node.data;\n        try list.append(node.val);              // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left != null) {\n            var tmp_node = try mem_allocator.create(L.Node);\n            tmp_node.data = node.left.?;\n            queue.append(tmp_node);             // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if (node.right != null) {\n            var tmp_node = try mem_allocator.create(L.Node);\n            tmp_node.data = node.right.?;\n            queue.append(tmp_node);             // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        }        \n    }\n    return list;\n}\n
    "},{"location":"chapter_tree/binary_tree_traversal/#2","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"
    • \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(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\u4e3a \\(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\u300d\uff0c\u4e5f\u79f0\u300c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22 depth-first search, 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\"\"\"\n    if root is None:\n        return\n    # \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    res.append(root.val)\n    pre_order(root=root.left)\n    pre_order(root=root.right)\n\ndef in_order(root: TreeNode | None):\n    \"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\n    if root is None:\n        return\n    # \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    in_order(root=root.left)\n    res.append(root.val)\n    in_order(root=root.right)\n\ndef post_order(root: TreeNode | None):\n    \"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\n    if root is None:\n        return\n    # \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    post_order(root=root.left)\n    post_order(root=root.right)\n    res.append(root.val)\n
    binary_tree_dfs.cpp
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root) {\n    if (root == nullptr)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    vec.push_back(root->val);\n    preOrder(root->left);\n    preOrder(root->right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root) {\n    if (root == nullptr)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root->left);\n    vec.push_back(root->val);\n    inOrder(root->right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root) {\n    if (root == nullptr)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root->left);\n    postOrder(root->right);\n    vec.push_back(root->val);\n}\n
    binary_tree_dfs.java
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode root) {\n    if (root == null)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.add(root.val);\n    preOrder(root.left);\n    preOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode root) {\n    if (root == null)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root.left);\n    list.add(root.val);\n    inOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode root) {\n    if (root == null)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root.left);\n    postOrder(root.right);\n    list.add(root.val);\n}\n
    binary_tree_dfs.cs
    /* \u524d\u5e8f\u904d\u5386 */\nvoid PreOrder(TreeNode? root) {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.Add(root.val!.Value);\n    PreOrder(root.left);\n    PreOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid InOrder(TreeNode? root) {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    InOrder(root.left);\n    list.Add(root.val!.Value);\n    InOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid PostOrder(TreeNode? root) {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    PostOrder(root.left);\n    PostOrder(root.right);\n    list.Add(root.val!.Value);\n}\n
    binary_tree_dfs.go
    /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(node *TreeNode) {\n    if node == nil {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    nums = append(nums, node.Val)\n    preOrder(node.Left)\n    preOrder(node.Right)\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(node *TreeNode) {\n    if node == nil {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(node.Left)\n    nums = append(nums, node.Val)\n    inOrder(node.Right)\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(node *TreeNode) {\n    if node == nil {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(node.Left)\n    postOrder(node.Right)\n    nums = append(nums, node.Val)\n}\n
    binary_tree_dfs.swift
    /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.append(root.val)\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root: root.left)\n    list.append(root.val)\n    inOrder(root: root.right)\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root: root.left)\n    postOrder(root: root.right)\n    list.append(root.val)\n}\n
    binary_tree_dfs.js
    /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root) {\n    if (root === null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.push(root.val);\n    preOrder(root.left);\n    preOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root) {\n    if (root === null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root.left);\n    list.push(root.val);\n    inOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root) {\n    if (root === null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root.left);\n    postOrder(root.right);\n    list.push(root.val);\n}\n
    binary_tree_dfs.ts
    /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root: TreeNode | null): void {\n    if (root === null) {\n        return;\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.push(root.val);\n    preOrder(root.left);\n    preOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root: TreeNode | null): void {\n    if (root === null) {\n        return;\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root.left);\n    list.push(root.val);\n    inOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root: TreeNode | null): void {\n    if (root === null) {\n        return;\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root.left);\n    postOrder(root.right);\n    list.push(root.val);\n}\n
    binary_tree_dfs.dart
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode? node) {\n  if (node == null) return;\n  // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n  list.add(node.val);\n  preOrder(node.left);\n  preOrder(node.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode? node) {\n  if (node == null) return;\n  // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n  inOrder(node.left);\n  list.add(node.val);\n  inOrder(node.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode? node) {\n  if (node == null) return;\n  // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n  postOrder(node.left);\n  postOrder(node.right);\n  list.add(node.val);\n}\n
    binary_tree_dfs.rs
    /* \u524d\u5e8f\u904d\u5386 */\nfn pre_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\n    let mut result = vec![];\n\n    if let Some(node) = root {\n        // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n        result.push(node.borrow().val);\n        result.append(&mut pre_order(node.borrow().left.as_ref()));\n        result.append(&mut pre_order(node.borrow().right.as_ref()));\n    }\n    result\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfn in_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\n    let mut result = vec![];\n\n    if let Some(node) = root {\n        // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n        result.append(&mut in_order(node.borrow().left.as_ref()));\n        result.push(node.borrow().val);\n        result.append(&mut in_order(node.borrow().right.as_ref()));\n    }\n    result\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfn post_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\n    let mut result = vec![];\n\n    if let Some(node) = root {\n        // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n        result.append(&mut post_order(node.borrow().left.as_ref()));\n        result.append(&mut post_order(node.borrow().right.as_ref()));\n        result.push(node.borrow().val);\n    }\n    result\n}\n
    binary_tree_dfs.c
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root, int *size) {\n    if (root == NULL)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    arr[(*size)++] = root->val;\n    preOrder(root->left, size);\n    preOrder(root->right, size);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root, int *size) {\n    if (root == NULL)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root->left, size);\n    arr[(*size)++] = root->val;\n    inOrder(root->right, size);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root, int *size) {\n    if (root == NULL)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root->left, size);\n    postOrder(root->right, size);\n    arr[(*size)++] = root->val;\n}\n
    binary_tree_dfs.zig
    // \u524d\u5e8f\u904d\u5386\nfn preOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    try list.append(root.?.val);\n    try preOrder(T, root.?.left);\n    try preOrder(T, root.?.right);\n}\n\n// \u4e2d\u5e8f\u904d\u5386\nfn inOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    try inOrder(T, root.?.left);\n    try list.append(root.?.val);\n    try inOrder(T, root.?.right);\n}\n\n// \u540e\u5e8f\u904d\u5386\nfn postOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    try postOrder(T, root.?.left);\n    try postOrder(T, root.?.right);\n    try 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\u4e3a \\(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\u4e3a \\(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

    \u5f00\u59cb\u9605\u8bfb \u4e0b\u8f7d\u4ee3\u7801 \u4e0b\u8f7d PDF

    \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

    \u52a8\u753b\u56fe\u89e3

    \u5185\u5bb9\u6e05\u6670\u6613\u61c2\u5b66\u4e60\u66f2\u7ebf\u5e73\u6ed1

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

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

    \u4e00\u952e\u8fd0\u884c

    \u5341\u4f59\u79cd\u7f16\u7a0b\u8bed\u8a00\u4ee3\u7801\u53ef\u76f4\u63a5\u8fd0\u884c

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

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

    \u4e92\u52a9\u5b66\u4e60

    \u6b22\u8fce\u8ba8\u8bba\u4e0e\u63d0\u95ee\u8bfb\u8005\u95f4\u643a\u624b\u5171\u8fdb

    \"\u8ffd\u98ce\u8d76\u6708\u83ab\u505c\u7559\"

    \u201c\u5e73\u829c\u5c3d\u5904\u662f\u6625\u5c71\u201d

    \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

    \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 30 \u4e07\u672c\u3002

    \u8d21\u732e

    \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 codingonion\u3001Gonglja\u3001gvenusleo\u3001hpstory\u3001justin\u2010tse\u3001krahets\u3001night-cruise\u3001nuomi1 \u548c Reanon \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

    codingonionRust, Zig GongljaC, C++ gvenusleoDart hpstoryC# justin-tseJS, TS krahetsJava, Python night-cruiseRust nuomi1Swift ReanonGo, C"},{"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 VS Code \u4f5c\u4e3a\u672c\u5730\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002\u8bbf\u95ee VS Code \u5b98\u7f51\uff0c\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u9009\u62e9\u76f8\u5e94\u7248\u672c\u7684 VS Code \u8fdb\u884c\u4e0b\u8f7d\u548c\u5b89\u88c5\u3002

    \u56fe 16-1 \u00a0 \u4ece\u5b98\u7f51\u4e0b\u8f7d VS Code

    VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \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 VS Code \u7684\u63d2\u4ef6\u5e02\u573a\u4e2d\u641c\u7d22 javascript \uff0c\u5b89\u88c5 JavaScript (ES6) code snippets \u3002
    3. \uff08\u53ef\u9009\uff09\u5728 VS Code \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 VS Code \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 VS Code \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\u8bfb\u8005\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 \\(O\\) \u8bb0\u53f7 big-\\(O\\) notation \u4f18\u5148\u961f\u5217 priority queue \u6e10\u8fd1\u4e0a\u754c asymptotic upper bound \u5806\u5316 heapify \u539f\u7801 sign-magnitude \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\u6982\u5ff5\u548c\u5b58\u50a8\u65b9\u5f0f\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\n    random_index = random.randint(0, len(nums) - 1)\n    # \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    random_num = nums[random_index]\n    return 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\n    int randomIndex = rand() % size;\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return 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\n    int randomIndex = ThreadLocalRandom.current().nextInt(0, nums.length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return randomNum;\n}\n
    array.cs
    /* \u968f\u673a\u8bbf\u95ee\u5143\u7d20 */\nint RandomAccess(int[] nums) {\n    Random random = new();\n    // \u5728\u533a\u95f4 [0, nums.Length) \u4e2d\u968f\u673a\u62bd\u53d6\u4e00\u4e2a\u6570\u5b57\n    int randomIndex = random.Next(nums.Length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return 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\n    randomIndex := rand.Intn(len(nums))\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    randomNum = nums[randomIndex]\n    return\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\n    let randomIndex = nums.indices.randomElement()!\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    let randomNum = nums[randomIndex]\n    return 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\n    const random_index = Math.floor(Math.random() * nums.length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    const random_num = nums[random_index];\n    return 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\n    const random_index = Math.floor(Math.random() * nums.length);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    const random_num = nums[random_index];\n    return 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\n  int randomIndex = Random().nextInt(nums.length);\n  // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n  int randomNum = nums[randomIndex];\n  return 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\n    let random_index = rand::thread_rng().gen_range(0..nums.len());\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    let random_num = nums[random_index];\n    random_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\n    int randomIndex = rand() % size;\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    int randomNum = nums[randomIndex];\n    return 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\n    var randomIndex = std.crypto.random.intRangeLessThan(usize, 0, nums.len);\n    // \u83b7\u53d6\u5e76\u8fd4\u56de\u968f\u673a\u5143\u7d20\n    var randomNum = nums[randomIndex];\n    return 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\n    for i in range(len(nums) - 1, index, -1):\n        nums[i] = nums[i - 1]\n    # \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = size - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = nums.length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = nums.Length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for i := len(nums) - 1; i > index; i-- {\n        nums[i] = nums[i-1]\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for i in nums.indices.dropFirst(index).reversed() {\n        nums[i] = nums[i - 1]\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (let i = nums.length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (let i = nums.length - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n  for (var i = nums.length - 1; i > index; i--) {\n    nums[i] = nums[i - 1];\n  }\n  // \u5c06 _num \u8d4b\u7ed9 index \u5904\u5143\u7d20\n  nums[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\n    for i in (index + 1..nums.len()).rev() {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for (int i = size - 1; i > index; i--) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    var i = nums.len - 1;\n    while (i > index) : (i -= 1) {\n        nums[i] = nums[i - 1];\n    }\n    // \u5c06 num \u8d4b\u7ed9 index \u5904\u7684\u5143\u7d20\n    nums[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\n    for i in range(index, len(nums) - 1):\n        nums[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\n    for (int i = index; i < size - 1; i++) {\n        nums[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\n    for (int i = index; i < nums.length - 1; i++) {\n        nums[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\n    for (int i = index; i < nums.Length - 1; i++) {\n        nums[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\n    for i := index; i < len(nums)-1; i++ {\n        nums[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\n    for i in nums.indices.dropFirst(index).dropLast() {\n        nums[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\n    for (let i = index; i < nums.length - 1; i++) {\n        nums[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\n    for (let i = index; i < nums.length - 1; i++) {\n        nums[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\n  for (var i = index; i < nums.length - 1; i++) {\n    nums[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\n    for i in index..nums.len() - 1 {\n        nums[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\n    for (int i = index; i < size - 1; i++) {\n        nums[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\n    var i = index;\n    while (i < nums.len - 1) : (i += 1) {\n        nums[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\"\"\"\n    count = 0\n    # \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i in range(len(nums)):\n        count += nums[i]\n    # \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for num in nums:\n        count += num\n    # \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\n    for i, num in enumerate(nums):\n        count += nums[i]\n        count += num\n
    array.cpp
    /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        count += nums[i];\n    }\n}\n
    array.java
    /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int[] nums) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < nums.length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (int num : nums) {\n        count += num;\n    }\n}\n
    array.cs
    /* \u904d\u5386\u6570\u7ec4 */\nvoid Traverse(int[] nums) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < nums.Length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    foreach (int num in nums) {\n        count += num;\n    }\n}\n
    array.go
    /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums []int) {\n    count := 0\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i := 0; i < len(nums); i++ {\n        count += nums[i]\n    }\n    count = 0\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for _, num := range nums {\n        count += num\n    }\n    // \u540c\u65f6\u904d\u5386\u6570\u636e\u7d22\u5f15\u548c\u5143\u7d20\n    for i, num := range nums {\n        count += nums[i]\n        count += num\n    }\n}\n
    array.swift
    /* \u904d\u5386\u6570\u7ec4 */\nfunc traverse(nums: [Int]) {\n    var count = 0\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i in nums.indices {\n        count += nums[i]\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for num in nums {\n        count += num\n    }\n}\n
    array.js
    /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums) {\n    let count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (let i = 0; i < nums.length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (const num of nums) {\n        count += num;\n    }\n}\n
    array.ts
    /* \u904d\u5386\u6570\u7ec4 */\nfunction traverse(nums: number[]): void {\n    let count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (let i = 0; i < nums.length; i++) {\n        count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (const num of nums) {\n        count += num;\n    }\n}\n
    array.dart
    /* \u904d\u5386\u6570\u7ec4\u5143\u7d20 */\nvoid traverse(List<int> nums) {\n  int count = 0;\n  // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n  for (var i = 0; i < nums.length; i++) {\n    count += nums[i];\n  }\n  // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n  for (int _num in nums) {\n    count += _num;\n  }\n  // \u901a\u8fc7 forEach \u65b9\u6cd5\u904d\u5386\u6570\u7ec4\n  nums.forEach((_num) {\n    count += _num;\n  });\n}\n
    array.rs
    /* \u904d\u5386\u6570\u7ec4 */\nfn traverse(nums: &[i32]) {\n    let mut _count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for i in 0..nums.len() {\n        _count += nums[i];\n    }\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for num in nums {\n        _count += num;\n    }\n}\n
    array.c
    /* \u904d\u5386\u6570\u7ec4 */\nvoid traverse(int *nums, int size) {\n    int count = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        count += nums[i];\n    }\n}\n
    array.zig
    // \u904d\u5386\u6570\u7ec4\nfn traverse(nums: []i32) void {\n    var count: i32 = 0;\n    // \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u6570\u7ec4\n    var i: i32 = 0;\n    while (i < nums.len) : (i += 1) {\n        count += nums[i];\n    }\n    count = 0;\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\u5143\u7d20\n    for (nums) |num| {\n        count += 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\"\"\"\n    for i in range(len(nums)):\n        if nums[i] == target:\n            return i\n    return -1\n
    array.cpp
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\n    for (int i = 0; i < size; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.java
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int[] nums, int target) {\n    for (int i = 0; i < nums.length; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.cs
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint Find(int[] nums, int target) {\n    for (int i = 0; i < nums.Length; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.go
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums []int, target int) (index int) {\n    index = -1\n    for i := 0; i < len(nums); i++ {\n        if nums[i] == target {\n            index = i\n            break\n        }\n    }\n    return\n}\n
    array.swift
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunc find(nums: [Int], target: Int) -> Int {\n    for i in nums.indices {\n        if nums[i] == target {\n            return i\n        }\n    }\n    return -1\n}\n
    array.js
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums, target) {\n    for (let i = 0; i < nums.length; i++) {\n        if (nums[i] === target) return i;\n    }\n    return -1;\n}\n
    array.ts
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfunction find(nums: number[], target: number): number {\n    for (let i = 0; i < nums.length; i++) {\n        if (nums[i] === target) {\n            return i;\n        }\n    }\n    return -1;\n}\n
    array.dart
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(List<int> nums, int target) {\n  for (var i = 0; i < nums.length; i++) {\n    if (nums[i] == target) return i;\n  }\n  return -1;\n}\n
    array.rs
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nfn find(nums: &[i32], target: i32) -> Option<usize> {\n    for i in 0..nums.len() {\n        if nums[i] == target {\n            return Some(i);\n        }\n    }\n    None\n}\n
    array.c
    /* \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20 */\nint find(int *nums, int size, int target) {\n    for (int i = 0; i < size; i++) {\n        if (nums[i] == target)\n            return i;\n    }\n    return -1;\n}\n
    array.zig
    // \u5728\u6570\u7ec4\u4e2d\u67e5\u627e\u6307\u5b9a\u5143\u7d20\nfn find(nums: []i32, target: i32) i32 {\n    for (nums, 0..) |num, i| {\n        if (num == target) return @intCast(i);\n    }\n    return -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\n    res = [0] * (len(nums) + enlarge)\n    # \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for i in range(len(nums)):\n        res[i] = nums[i]\n    # \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    int *res = new int[size + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        res[i] = nums[i];\n    }\n    // \u91ca\u653e\u5185\u5b58\n    delete[] nums;\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    int[] res = new int[nums.length + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < nums.length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    int[] res = new int[nums.Length + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < nums.Length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    res := make([]int, len(nums)+enlarge)\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for i, num := range nums {\n        res[i] = num\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    var 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\n    for i in nums.indices {\n        res[i] = nums[i]\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    const 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\n    for (let i = 0; i < nums.length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    const 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\n    for (let i = 0; i < nums.length; i++) {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n  List<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\n  for (var i = 0; i < nums.length; i++) {\n    res[i] = nums[i];\n  }\n  // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n  return 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\n    let mut res: Vec<i32> = vec![0; nums.len() + enlarge];\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\n    for i in 0..nums.len() {\n        res[i] = nums[i];\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    res\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\n    int *res = (int *)malloc(sizeof(int) * (size + enlarge));\n    // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    for (int i = 0; i < size; i++) {\n        res[i] = nums[i];\n    }\n    // \u521d\u59cb\u5316\u6269\u5c55\u540e\u7684\u7a7a\u95f4\n    for (int i = size; i < size + enlarge; i++) {\n        res[i] = 0;\n    }\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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\n    var 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\n    std.mem.copy(i32, res, nums);\n    // \u8fd4\u56de\u6269\u5c55\u540e\u7684\u65b0\u6570\u7ec4\n    return 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 null\u3001nullptr \u548c None \u3002
    • \u5728 C\u3001C++\u3001Go \u548c Rust \u7b49\u652f\u6301\u6307\u9488\u7684\u8bed\u8a00\u4e2d\uff0c\u4e0a\u8ff0\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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val               # \u8282\u70b9\u503c\n        self.next: ListNode | None = None # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n
    /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct ListNode {\n    int val;         // \u8282\u70b9\u503c\n    ListNode *next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n    ListNode(int x) : val(x), next(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    int val;        // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    ListNode(int x) { val = x; }  // \u6784\u9020\u51fd\u6570\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode(int x) {  //\u6784\u9020\u51fd\u6570\n    int val = x;         // \u8282\u70b9\u503c\n    ListNode? next;      // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype ListNode struct {\n    Val  int       // \u8282\u70b9\u503c\n    Next *ListNode // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n}\n\n// NewListNode \u6784\u9020\u51fd\u6570\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u94fe\u8868\nfunc NewListNode(val int) *ListNode {\n    return &ListNode{\n        Val:  val,\n        Next: nil,\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    var val: Int // \u8282\u70b9\u503c\n    var next: ListNode? // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n\n    init(x: Int) { // \u6784\u9020\u51fd\u6570\n        val = x\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    constructor(val, next) {\n        this.val = (val === undefined ? 0 : val);       // \u8282\u70b9\u503c\n        this.next = (next === undefined ? null : next); // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    val: number;\n    next: ListNode | null;\n    constructor(val?: number, next?: ListNode | null) {\n        this.val = val === undefined ? 0 : val;        // \u8282\u70b9\u503c\n        this.next = next === undefined ? null : next;  // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n
    /* \u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n  int val; // \u8282\u70b9\u503c\n  ListNode? next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n  ListNode(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 {\n    val: i32, // \u8282\u70b9\u503c\n    next: 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 {\n    int val;               // \u8282\u70b9\u503c\n    struct ListNode *next; // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\n    ListNode *node;\n    node = (ListNode *) malloc(sizeof(ListNode));\n    node->val = val;\n    node->next = NULL;\n    return node;\n}\n
    // \u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        val: T = 0, // \u8282\u70b9\u503c\n        next: ?*Self = null, // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u6307\u9488\n\n        // \u6784\u9020\u51fd\u6570\n        pub fn init(self: *Self, x: i32) void {\n            self.val = x;\n            self.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\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\"\"\"\n    n1 = n0.next\n    P.next = n1\n    n0.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) {\n    ListNode *n1 = n0->next;\n    P->next = n1;\n    n0->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) {\n    ListNode n1 = n0.next;\n    P.next = n1;\n    n0.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) {\n    ListNode? n1 = n0.next;\n    P.next = n1;\n    n0.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) {\n    n1 := n0.Next\n    P.Next = n1\n    n0.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) {\n    let n1 = n0.next\n    P.next = n1\n    n0.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) {\n    const n1 = n0.next;\n    P.next = n1;\n    n0.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 {\n    const n1 = n0.next;\n    P.next = n1;\n    n0.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) {\n  ListNode? n1 = n0.next;\n  P.next = n1;\n  n0.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>>>) {\n    let n1 =  n0.borrow_mut().next.take();\n    P.borrow_mut().next = n1;\n    n0.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) {\n    ListNode *n1 = n0->next;\n    P->next = n1;\n    n0->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 {\n    var n1 = n0.?.next;\n    P.?.next = n1;\n    n0.?.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\"\"\"\n    if not n0.next:\n        return\n    # n0 -> P -> n1\n    P = n0.next\n    n1 = P.next\n    n0.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) {\n    if (n0->next == nullptr)\n        return;\n    // n0 -> P -> n1\n    ListNode *P = n0->next;\n    ListNode *n1 = P->next;\n    n0->next = n1;\n    // \u91ca\u653e\u5185\u5b58\n    delete 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) {\n    if (n0.next == null)\n        return;\n    // n0 -> P -> n1\n    ListNode P = n0.next;\n    ListNode n1 = P.next;\n    n0.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) {\n    if (n0.next == null)\n        return;\n    // n0 -> P -> n1\n    ListNode P = n0.next;\n    ListNode? n1 = P.next;\n    n0.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) {\n    if n0.Next == nil {\n        return\n    }\n    // n0 -> P -> n1\n    P := n0.Next\n    n1 := P.Next\n    n0.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) {\n    if n0.next == nil {\n        return\n    }\n    // n0 -> P -> n1\n    let P = n0.next\n    let n1 = P?.next\n    n0.next = n1\n    P?.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) {\n    if (!n0.next) return;\n    // n0 -> P -> n1\n    const P = n0.next;\n    const n1 = P.next;\n    n0.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 {\n    if (!n0.next) {\n        return;\n    }\n    // n0 -> P -> n1\n    const P = n0.next;\n    const n1 = P.next;\n    n0.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) {\n  if (n0.next == null) return;\n  // n0 -> P -> n1\n  ListNode P = n0.next!;\n  ListNode? n1 = P.next;\n  n0.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>>>) {\n    if n0.borrow().next.is_none() {return};\n    // n0 -> P -> n1\n    let P = n0.borrow_mut().next.take();\n    if let Some(node) = P {\n        let n1 = node.borrow_mut().next.take();\n        n0.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) {\n    if (!n0->next)\n        return;\n    // n0 -> P -> n1\n    ListNode *P = n0->next;\n    ListNode *n1 = P->next;\n    n0->next = n1;\n    // \u91ca\u653e\u5185\u5b58\n    free(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 {\n    if (n0.?.next == null) return;\n    // n0 -> P -> n1\n    var P = n0.?.next;\n    var n1 = P.?.next;\n    n0.?.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\"\"\"\n    for _ in range(index):\n        if not head:\n            return None\n        head = head.next\n    return head\n
    linked_list.cpp
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == nullptr)\n            return nullptr;\n        head = head->next;\n    }\n    return head;\n}\n
    linked_list.java
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode access(ListNode head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == null)\n            return null;\n        head = head.next;\n    }\n    return head;\n}\n
    linked_list.cs
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? Access(ListNode? head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == null)\n            return null;\n        head = head.next;\n    }\n    return 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 {\n    for i := 0; i < index; i++ {\n        if head == nil {\n            return nil\n        }\n        head = head.Next\n    }\n    return 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? {\n    var head: ListNode? = head\n    for _ in 0 ..< index {\n        if head == nil {\n            return nil\n        }\n        head = head?.next\n    }\n    return head\n}\n
    linked_list.js
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nfunction access(head, index) {\n    for (let i = 0; i < index; i++) {\n        if (!head) {\n            return null;\n        }\n        head = head.next;\n    }\n    return 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 {\n    for (let i = 0; i < index; i++) {\n        if (!head) {\n            return null;\n        }\n        head = head.next;\n    }\n    return head;\n}\n
    linked_list.dart
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode? access(ListNode? head, int index) {\n  for (var i = 0; i < index; i++) {\n    if (head == null) return null;\n    head = head.next;\n  }\n  return 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>>> {\n    if index <= 0 {return head};\n    if let Some(node) = &head.borrow_mut().next {\n        return access(node.clone(), index - 1);\n    }\n    return head;\n}\n
    linked_list.c
    /* \u8bbf\u95ee\u94fe\u8868\u4e2d\u7d22\u5f15\u4e3a index \u7684\u8282\u70b9 */\nListNode *access(ListNode *head, int index) {\n    for (int i = 0; i < index; i++) {\n        if (head == NULL)\n            return NULL;\n        head = head->next;\n    }\n    return 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) {\n    var head = node;\n    var i: i32 = 0;\n    while (i < index) : (i += 1) {\n        head = head.?.next;\n        if (head == null) return null;\n    }\n    return 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\"\"\"\n    index = 0\n    while head:\n        if head.val == target:\n            return index\n        head = head.next\n        index += 1\n    return -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) {\n    int index = 0;\n    while (head != nullptr) {\n        if (head->val == target)\n            return index;\n        head = head->next;\n        index++;\n    }\n    return -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) {\n    int index = 0;\n    while (head != null) {\n        if (head.val == target)\n            return index;\n        head = head.next;\n        index++;\n    }\n    return -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) {\n    int index = 0;\n    while (head != null) {\n        if (head.val == target)\n            return index;\n        head = head.next;\n        index++;\n    }\n    return -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 {\n    index := 0\n    for head != nil {\n        if head.Val == target {\n            return index\n        }\n        head = head.Next\n        index++\n    }\n    return -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 {\n    var head: ListNode? = head\n    var index = 0\n    while head != nil {\n        if head?.val == target {\n            return index\n        }\n        head = head?.next\n        index += 1\n    }\n    return -1\n}\n
    linked_list.js
    /* \u5728\u94fe\u8868\u4e2d\u67e5\u627e\u503c\u4e3a target \u7684\u9996\u4e2a\u8282\u70b9 */\nfunction find(head, target) {\n    let index = 0;\n    while (head !== null) {\n        if (head.val === target) {\n            return index;\n        }\n        head = head.next;\n        index += 1;\n    }\n    return -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 {\n    let index = 0;\n    while (head !== null) {\n        if (head.val === target) {\n            return index;\n        }\n        head = head.next;\n        index += 1;\n    }\n    return -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) {\n  int index = 0;\n  while (head != null) {\n    if (head.val == target) {\n      return index;\n    }\n    head = head.next;\n    index++;\n  }\n  return -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 {\n    if head.borrow().val == target {return index};\n    if let Some(node) = &head.borrow_mut().next {\n        return find(node.clone(), target, index + 1);\n    }\n    return -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) {\n    int index = 0;\n    while (head) {\n        if (head->val == target)\n            return index;\n        head = head->next;\n        index++;\n    }\n    return -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 {\n    var head = node;\n    var index: i32 = 0;\n    while (head != null) {\n        if (head.?.val == target) return index;\n        head = head.?.next;\n        index += 1;\n    }\n    return -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 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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val                # \u8282\u70b9\u503c\n        self.next: ListNode | None = None  # \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n        self.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 {\n    int val;         // \u8282\u70b9\u503c\n    ListNode *next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    ListNode *prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n    ListNode(int x) : val(x), next(nullptr), prev(nullptr) {}  // \u6784\u9020\u51fd\u6570\n};\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    int val;        // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    ListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n    ListNode(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\n    int val = x;    // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    ListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype DoublyListNode struct {\n    Val  int             // \u8282\u70b9\u503c\n    Next *DoublyListNode // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    Prev *DoublyListNode // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n\n// NewDoublyListNode \u521d\u59cb\u5316\nfunc NewDoublyListNode(val int) *DoublyListNode {\n    return &DoublyListNode{\n        Val:  val,\n        Next: nil,\n        Prev: nil,\n    }\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    var val: Int // \u8282\u70b9\u503c\n    var next: ListNode? // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    var prev: ListNode? // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n\n    init(x: Int) { // \u6784\u9020\u51fd\u6570\n        val = x\n    }\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b */\nclass ListNode {\n    constructor(val, next, prev) {\n        this.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\n        this.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n        this.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 {\n    val: number;\n    next: ListNode | null;\n    prev: ListNode | null;\n    constructor(val?: number, next?: ListNode | null, prev?: ListNode | null) {\n        this.val = val  ===  undefined ? 0 : val;        // \u8282\u70b9\u503c\n        this.next = next  ===  undefined ? null : next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n        this.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 {\n    int val;        // \u8282\u70b9\u503c\n    ListNode next;  // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u5f15\u7528\n    ListNode prev;  // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u5f15\u7528\n    ListNode(this.val, [this.next, this.prev]);  // \u6784\u9020\u51fd\u6570\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\u578b */\n#[derive(Debug)]\nstruct ListNode {\n    val: i32, // \u8282\u70b9\u503c\n    next: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    prev: Option<Rc<RefCell<ListNode>>>, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nimpl ListNode {\n    fn new(val: i32) -> Self {\n        ListNode {\n            val,\n            next: None,\n            prev: None,\n        }\n    }\n}\n
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct ListNode {\n    int val;               // \u8282\u70b9\u503c\n    struct ListNode *next; // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n    struct ListNode *prev; // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n} ListNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nListNode *newListNode(int val) {\n    ListNode *node;\n    node = (ListNode *) malloc(sizeof(ListNode));\n    node->val = val;\n    node->next = NULL;\n    node->prev = NULL;\n    return node;\n}\n
    // \u53cc\u5411\u94fe\u8868\u8282\u70b9\u7c7b\npub fn ListNode(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        val: T = 0, // \u8282\u70b9\u503c\n        next: ?*Self = null, // \u6307\u5411\u540e\u7ee7\u8282\u70b9\u7684\u6307\u9488\n        prev: ?*Self = null, // \u6307\u5411\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\n\n        // \u6784\u9020\u51fd\u6570\n        pub fn init(self: *Self, x: i32) void {\n            self.val = x;\n            self.next = null;\n            self.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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\n# \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n\n# \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\nnums.insert(3, 6)  # \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\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\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\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.add(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.Add(1);\nnums.Add(3);\nnums.Add(2);\nnums.Add(5);\nnums.Add(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.Insert(3, 6);\n\n/* \u5220\u9664\u5143\u7d20 */\nnums.RemoveAt(3);\n
    list_test.go
    /* \u6e05\u7a7a\u5217\u8868 */\nnums = nil\n\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\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\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.append(1)\nnums.append(3)\nnums.append(2)\nnums.append(5)\nnums.append(4)\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(6, at: 3) // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
    list.ts
    /* \u6e05\u7a7a\u5217\u8868 */\nnums.length = 0;\n\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.splice(3, 0, 6);\n\n/* \u5220\u9664\u5143\u7d20 */\nnums.splice(3, 1);\n
    list.dart
    /* \u6e05\u7a7a\u5217\u8868 */\nnums.clear();\n\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.add(1);\nnums.add(3);\nnums.add(2);\nnums.add(5);\nnums.add(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nnums.push(1);\nnums.push(3);\nnums.push(2);\nnums.push(5);\nnums.push(4);\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nnums.insert(3, 6);  // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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\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\n// \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\ntry nums.insert(3, 6); // \u5728\u7d22\u5f15 3 \u5904\u63d2\u5165\u6570\u5b57 6\n\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)):\n    count += nums[i]\n\n# \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\nfor num in nums:\n    count += num\n
    list.cpp
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (int num : nums) {\n    count += num;\n}\n
    list.java
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.size(); i++) {\n    count += nums.get(i);\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\nfor (int num : nums) {\n    count += num;\n}\n
    list.cs
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (int i = 0; i < nums.Count; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nforeach (int num in nums) {\n    count += num;\n}\n
    list_test.go
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\ncount := 0\nfor i := 0; i < len(nums); i++ {\n    count += nums[i]\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor _, num := range nums {\n    count += num\n}\n
    list.swift
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nvar count = 0\nfor i in nums.indices {\n    count += nums[i]\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0\nfor num in nums {\n    count += num\n}\n
    list.js
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\n    count += num;\n}\n
    list.ts
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nlet count = 0;\nfor (let i = 0; i < nums.length; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (const num of nums) {\n    count += num;\n}\n
    list.dart
    /* \u901a\u8fc7\u7d22\u5f15\u904d\u5386\u5217\u8868 */\nint count = 0;\nfor (var i = 0; i < nums.length; i++) {\n    count += nums[i];\n}\n\n/* \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20 */\ncount = 0;\nfor (var num in nums) {\n    count += 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\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) {\n    count += nums[i];\n}\n\n// \u76f4\u63a5\u904d\u5386\u5217\u8868\u5143\u7d20\ncount = 0;\nfor (nums.items) |num| {\n    count += 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 */  \nnums.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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._capacity: int = 10  # \u5217\u8868\u5bb9\u91cf\n        self._arr: list[int] = [0] * self._capacity  # \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n        self._size: int = 0  # \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n        self._extend_ratio: int = 2  # \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\"\"\"\n        return self._size\n\n    def capacity(self) -> int:\n        \"\"\"\u83b7\u53d6\u5217\u8868\u5bb9\u91cf\"\"\"\n        return self._capacity\n\n    def get(self, index: int) -> int:\n        \"\"\"\u8bbf\u95ee\u5143\u7d20\"\"\"\n        # \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        return self._arr[index]\n\n    def set(self, num: int, index: int):\n        \"\"\"\u66f4\u65b0\u5143\u7d20\"\"\"\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        self._arr[index] = num\n\n    def 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\n        if self.size() == self.capacity():\n            self.extend_capacity()\n        self._arr[self._size] = num\n        self._size += 1\n\n    def insert(self, num: int, index: int):\n        \"\"\"\u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\"\"\"\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        # \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if self._size == self.capacity():\n            self.extend_capacity()\n        # \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for j in range(self._size - 1, index - 1, -1):\n            self._arr[j + 1] = self._arr[j]\n        self._arr[index] = num\n        # \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self._size += 1\n\n    def remove(self, index: int) -> int:\n        \"\"\"\u5220\u9664\u5143\u7d20\"\"\"\n        if index < 0 or index >= self._size:\n            raise IndexError(\"\u7d22\u5f15\u8d8a\u754c\")\n        num = self._arr[index]\n        # \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for j in range(index, self._size - 1):\n            self._arr[j] = self._arr[j + 1]\n        # \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self._size -= 1\n        # \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num\n\n    def 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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        self._arr = self._arr + [0] * self.capacity() * (self._extend_ratio - 1)\n        # \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        self._capacity = len(self._arr)\n\n    def to_array(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u6709\u6548\u957f\u5ea6\u7684\u5217\u8868\"\"\"\n        return self._arr[: self._size]\n
    my_list.cpp
    /* \u5217\u8868\u7c7b */\nclass MyList {\n  private:\n    int *arr;             // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    int arrCapacity = 10; // \u5217\u8868\u5bb9\u91cf\n    int arrSize = 0;      // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    int extendRatio = 2;   // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    MyList() {\n        arr = new int[arrCapacity];\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~MyList() {\n        delete[] arr;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    int size() {\n        return arrSize;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    int capacity() {\n        return arrCapacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    int get(int index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        return arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    void set(int index, int num) {\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    void add(int num) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size() == capacity())\n            extendCapacity();\n        arr[size()] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    void insert(int index, int num) {\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size() == capacity())\n            extendCapacity();\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (int 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        arrSize++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    int remove(int index) {\n        if (index < 0 || index >= size())\n            throw out_of_range(\"\u7d22\u5f15\u8d8a\u754c\");\n        int num = arr[index];\n        // \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (int j = index; j < size() - 1; j++) {\n            arr[j] = arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    void extendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\n        int newCapacity = capacity() * extendRatio;\n        int *tmp = arr;\n        arr = new int[newCapacity];\n        // \u5c06\u539f\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        for (int i = 0; i < size(); i++) {\n            arr[i] = tmp[i];\n        }\n        // \u91ca\u653e\u5185\u5b58\n        delete[] tmp;\n        arrCapacity = newCapacity;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Vector \u7528\u4e8e\u6253\u5370 */\n    vector<int> toVector() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        vector<int> vec(size());\n        for (int i = 0; i < size(); i++) {\n            vec[i] = arr[i];\n        }\n        return vec;\n    }\n};\n
    my_list.java
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private int[] arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private int capacity = 10; // \u5217\u8868\u5bb9\u91cf\n    private int size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private int extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public MyList() {\n        arr = new int[capacity];\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\n    public int size() {\n        return size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    public int capacity() {\n        return capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    public int get(int index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        return arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    public void set(int index, int num) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    public void add(int num) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size == capacity())\n            extendCapacity();\n        arr[size] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        size++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    public void insert(int index, int num) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (size == capacity())\n            extendCapacity();\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (int 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\n    /* \u5220\u9664\u5143\u7d20 */\n    public int remove(int index) {\n        if (index < 0 || index >= size)\n            throw new IndexOutOfBoundsException(\"\u7d22\u5f15\u8d8a\u754c\");\n        int num = arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (int 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\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    public 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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        arr = Arrays.copyOf(arr, capacity() * extendRatio);\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        capacity = arr.length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    public int[] toArray() {\n        int size = size();\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] arr = new int[size];\n        for (int i = 0; i < size; i++) {\n            arr[i] = get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.cs
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private int[] arr;           // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private int arrCapacity = 10;    // \u5217\u8868\u5bb9\u91cf\n    private int arrSize = 0;         // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private readonly int extendRatio = 2;  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public MyList() {\n        arr = new int[arrCapacity];\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    public int Size() {\n        return arrSize;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    public int Capacity() {\n        return arrCapacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    public int Get(int index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        return arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    public void Set(int index, int num) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    public void Add(int num) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (arrSize == arrCapacity)\n            ExtendCapacity();\n        arr[arrSize] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    public void Insert(int index, int num) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if (arrSize == arrCapacity)\n            ExtendCapacity();\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (int j = arrSize - 1; j >= index; j--) {\n            arr[j + 1] = arr[j];\n        }\n        arr[index] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    public int Remove(int index) {\n        if (index < 0 || index >= arrSize)\n            throw new IndexOutOfRangeException(\"\u7d22\u5f15\u8d8a\u754c\");\n        int num = arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (int j = index; j < arrSize - 1; j++) {\n            arr[j] = arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        arrSize--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    public void ExtendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a arrCapacity * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        Array.Resize(ref arr, arrCapacity * extendRatio);\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        arrCapacity = arr.Length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    public int[] ToArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] arr = new int[arrSize];\n        for (int i = 0; i < arrSize; i++) {\n            arr[i] = Get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.go
    /* \u5217\u8868\u7c7b */\ntype myList struct {\n    arrCapacity int\n    arr         []int\n    arrSize     int\n    extendRatio int\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nfunc newMyList() *myList {\n    return &myList{\n        arrCapacity: 10,              // \u5217\u8868\u5bb9\u91cf\n        arr:         make([]int, 10), // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n        arrSize:     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    }\n}\n\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09 */\nfunc (l *myList) size() int {\n    return l.arrSize\n}\n\n/*  \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nfunc (l *myList) capacity() int {\n    return l.arrCapacity\n}\n\n/* \u8bbf\u95ee\u5143\u7d20 */\nfunc (l *myList) get(index int) int {\n    // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    return l.arr[index]\n}\n\n/* \u66f4\u65b0\u5143\u7d20 */\nfunc (l *myList) set(num, index int) {\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    l.arr[index] = num\n}\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\n    if l.arrSize == l.arrCapacity {\n        l.extendCapacity()\n    }\n    l.arr[l.arrSize] = num\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    l.arrSize++\n}\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nfunc (l *myList) insert(num, index int) {\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n    if l.arrSize == l.arrCapacity {\n        l.extendCapacity()\n    }\n    // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    for j := l.arrSize - 1; j >= index; j-- {\n        l.arr[j+1] = l.arr[j]\n    }\n    l.arr[index] = num\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    l.arrSize++\n}\n\n/* \u5220\u9664\u5143\u7d20 */\nfunc (l *myList) remove(index int) int {\n    if index < 0 || index >= l.arrSize {\n        panic(\"\u7d22\u5f15\u8d8a\u754c\")\n    }\n    num := l.arr[index]\n    // \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n    for j := index; j < l.arrSize-1; j++ {\n        l.arr[j] = l.arr[j+1]\n    }\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    l.arrSize--\n    // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n    return num\n}\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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    l.arr = append(l.arr, make([]int, l.arrCapacity*(l.extendRatio-1))...)\n    // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n    l.arrCapacity = len(l.arr)\n}\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\n    return l.arr[:l.arrSize]\n}\n
    my_list.swift
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private var arr: [Int] // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private var _capacity = 10 // \u5217\u8868\u5bb9\u91cf\n    private var _size = 0 // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private let extendRatio = 2 // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init() {\n        arr = Array(repeating: 0, count: _capacity)\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    func size() -> Int {\n        _size\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    func capacity() -> Int {\n        _capacity\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    func get(index: Int) -> Int {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\u5219\u629b\u51fa\u9519\u8bef\uff0c\u4e0b\u540c\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        return arr[index]\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    func set(index: Int, num: Int) {\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        arr[index] = num\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    func add(num: Int) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if _size == _capacity {\n            extendCapacity()\n        }\n        arr[_size] = num\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        _size += 1\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    func insert(index: Int, num: Int) {\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if _size == _capacity {\n            extendCapacity()\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for j in sequence(first: _size - 1, next: { $0 >= index + 1 ? $0 - 1 : nil }) {\n            arr[j + 1] = arr[j]\n        }\n        arr[index] = num\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        _size += 1\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    @discardableResult\n    func remove(index: Int) -> Int {\n        if index < 0 || index >= _size {\n            fatalError(\"\u7d22\u5f15\u8d8a\u754c\")\n        }\n        let num = arr[index]\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for j in index ..< (_size - 1) {\n            arr[j] = arr[j + 1]\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        _size -= 1\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    func extendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        arr = arr + Array(repeating: 0, count: _capacity * (extendRatio - 1))\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        _capacity = arr.count\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    func toArray() -> [Int] {\n        var arr = Array(repeating: 0, count: _size)\n        for i in 0 ..< _size {\n            arr[i] = get(index: i)\n        }\n        return 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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#arr = new Array(this.#capacity);\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    size() {\n        return this.#size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    capacity() {\n        return this.#capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    get(index) {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        return this.#arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    set(index, num) {\n        if (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        this.#arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    add(num) {\n        // \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\n        if (this.#size === this.#capacity) {\n            this.extendCapacity();\n        }\n        // \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\n        this.#arr[this.#size] = num;\n        this.#size++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    insert(index, num) {\n        if (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\n        if (this.#size === this.#capacity) {\n            this.extendCapacity();\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (let j = this.#size - 1; j >= index; j--) {\n            this.#arr[j + 1] = this.#arr[j];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this.#arr[index] = num;\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    remove(index) {\n        if (index < 0 || index >= this.#size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        let num = this.#arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (let j = index; j < this.#size - 1; j++) {\n            this.#arr[j] = this.#arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this.#size--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    extendCapacity() {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 extendRatio \u500d\u7684\u65b0\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        this.#arr = this.#arr.concat(\n            new Array(this.capacity() * (this.#extendRatio - 1))\n        );\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        this.#capacity = this.#arr.length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    toArray() {\n        let size = this.size();\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(size);\n        for (let i = 0; i < size; i++) {\n            arr[i] = this.get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.ts
    /* \u5217\u8868\u7c7b */\nclass MyList {\n    private arr: Array<number>; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    private _capacity: number = 10; // \u5217\u8868\u5bb9\u91cf\n    private _size: number = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    private extendRatio: number = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.arr = new Array(this._capacity);\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    public size(): number {\n        return this._size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    public capacity(): number {\n        return this._capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    public get(index: number): number {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        return this.arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    public set(index: number, num: number): void {\n        if (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        this.arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    public add(num: number): void {\n        // \u5982\u679c\u957f\u5ea6\u7b49\u4e8e\u5bb9\u91cf\uff0c\u5219\u9700\u8981\u6269\u5bb9\n        if (this._size === this._capacity) this.extendCapacity();\n        // \u5c06\u65b0\u5143\u7d20\u6dfb\u52a0\u5230\u5217\u8868\u5c3e\u90e8\n        this.arr[this._size] = num;\n        this._size++;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    public insert(index: number, num: number): void {\n        if (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\n        if (this._size === this._capacity) {\n            this.extendCapacity();\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for (let j = this._size - 1; j >= index; j--) {\n            this.arr[j + 1] = this.arr[j];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this.arr[index] = num;\n        this._size++;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    public remove(index: number): number {\n        if (index < 0 || index >= this._size) throw new Error('\u7d22\u5f15\u8d8a\u754c');\n        let num = this.arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for (let j = index; j < this._size - 1; j++) {\n            this.arr[j] = this.arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        this._size--;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    public extendCapacity(): void {\n        // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        this.arr = this.arr.concat(\n            new Array(this.capacity() * (this.extendRatio - 1))\n        );\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        this._capacity = this.arr.length;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    public toArray(): number[] {\n        let size = this.size();\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(size);\n        for (let i = 0; i < size; i++) {\n            arr[i] = this.get(i);\n        }\n        return arr;\n    }\n}\n
    my_list.dart
    /* \u5217\u8868\u7c7b */\nclass MyList {\n  late List<int> _arr; // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n  int _capacity = 10; // \u5217\u8868\u5bb9\u91cf\n  int _size = 0; // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n  int _extendRatio = 2; // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  MyList() {\n    _arr = List.filled(_capacity, 0);\n  }\n\n  /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n  int size() => _size;\n\n  /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n  int capacity() => _capacity;\n\n  /* \u8bbf\u95ee\u5143\u7d20 */\n  int get(int index) {\n    if (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n    return _arr[index];\n  }\n\n  /* \u66f4\u65b0\u5143\u7d20 */\n  void set(int index, int _num) {\n    if (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n    _arr[index] = _num;\n  }\n\n  /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n  void add(int _num) {\n    // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n    if (_size == _capacity) extendCapacity();\n    _arr[_size] = _num;\n    // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n    _size++;\n  }\n\n  /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n  void insert(int index, int _num) {\n    if (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\n    if (_size == _capacity) extendCapacity();\n    // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    for (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\n  /* \u5220\u9664\u5143\u7d20 */\n  int remove(int index) {\n    if (index >= _size) throw RangeError('\u7d22\u5f15\u8d8a\u754c');\n    int _num = _arr[index];\n    // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n    for (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\u7684\u5143\u7d20\n    return _num;\n  }\n\n  /* \u5217\u8868\u6269\u5bb9 */\n  void extendCapacity() {\n    // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a\u539f\u6570\u7ec4 _extendRatio \u500d\u7684\u65b0\u6570\u7ec4\n    final _newNums = List.filled(_capacity * _extendRatio, 0);\n    // \u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n    List.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\n  /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n  List<int> toArray() {\n    List<int> arr = [];\n    for (var i = 0; i < _size; i++) {\n      arr.add(get(i));\n    }\n    return arr;\n  }\n}\n
    my_list.rs
    /* \u5217\u8868\u7c7b */\n#[allow(dead_code)]\nstruct MyList {\n    arr: Vec<i32>,       // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    capacity: usize,      // \u5217\u8868\u5bb9\u91cf\n    size: usize,          // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n    extend_ratio: usize,  // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n}\n\n#[allow(unused,unused_comparisons)]\nimpl MyList {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(capacity: usize) -> Self {\n        let mut vec = Vec::new(); \n        vec.resize(capacity, 0);\n        Self {\n            arr: vec,\n            capacity,\n            size: 0,\n            extend_ratio: 2,\n        }\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09*/\n    pub fn size(&self) -> usize {\n        return self.size;\n    }\n\n    /* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\n    pub fn capacity(&self) -> usize {\n        return self.capacity;\n    }\n\n    /* \u8bbf\u95ee\u5143\u7d20 */\n    pub fn get(&self, index: usize) -> i32 {\n        // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n        if index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n        return self.arr[index];\n    }\n\n    /* \u66f4\u65b0\u5143\u7d20 */\n    pub fn set(&mut self, index: usize, num: i32) {\n        if index >= self.size {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n        self.arr[index] = num;\n    }\n\n    /* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\n    pub fn add(&mut self, num: i32) {\n        // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n        if self.size == self.capacity() {\n            self.extend_capacity();\n        }\n        self.arr[self.size] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self.size += 1;\n    }\n\n    /* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\n    pub fn insert(&mut self, index: usize, num: i32) {\n        if 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\n        if self.size == self.capacity() {\n            self.extend_capacity();\n        }\n        // \u5c06\u7d22\u5f15 index \u4ee5\u53ca\u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        for j in (index..self.size).rev() {\n            self.arr[j + 1] = self.arr[j];\n        }\n        self.arr[index] = num;\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self.size += 1;\n    }\n\n    /* \u5220\u9664\u5143\u7d20 */\n    pub fn remove(&mut self, index: usize) -> i32 {\n        if index >= self.size() {panic!(\"\u7d22\u5f15\u8d8a\u754c\")};\n        let num = self.arr[index];\n        // \u5c06\u7d22\u5f15 index \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n        for j in (index..self.size - 1) {\n            self.arr[j] = self.arr[j + 1];\n        }\n        // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n        self.size -= 1;\n        // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n        return num;\n    }\n\n    /* \u5217\u8868\u6269\u5bb9 */\n    pub 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\u590d\u5236\u5230\u65b0\u6570\u7ec4\n        let new_capacity = self.capacity * self.extend_ratio;\n        self.arr.resize(new_capacity, 0);\n        // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n        self.capacity = new_capacity;\n    }\n\n    /* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4 */\n    pub fn to_array(&mut self) -> Vec<i32> {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        let mut arr = Vec::new();\n        for i in 0..self.size {\n            arr.push(self.get(i));\n        }\n        arr\n    }\n}\n
    my_list.c
    /* \u5217\u8868\u7c7b */\ntypedef struct {\n    int *arr;        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n    int capacity;    // \u5217\u8868\u5bb9\u91cf\n    int size;        // \u5217\u8868\u5927\u5c0f\n    int extendRatio; // \u5217\u8868\u6bcf\u6b21\u6269\u5bb9\u7684\u500d\u6570\n} MyList;\n\n/* \u6784\u9020\u51fd\u6570 */\nMyList *newMyList() {\n    MyList *nums = malloc(sizeof(MyList));\n    nums->capacity = 10;\n    nums->arr = malloc(sizeof(int) * nums->capacity);\n    nums->size = 0;\n    nums->extendRatio = 2;\n    return nums;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delMyList(MyList *nums) {\n    free(nums->arr);\n    free(nums);\n}\n\n/* \u83b7\u53d6\u5217\u8868\u957f\u5ea6 */\nint size(MyList *nums) {\n    return nums->size;\n}\n\n/* \u83b7\u53d6\u5217\u8868\u5bb9\u91cf */\nint capacity(MyList *nums) {\n    return nums->capacity;\n}\n\n/* \u8bbf\u95ee\u5143\u7d20 */\nint get(MyList *nums, int index) {\n    assert(index >= 0 && index < nums->size);\n    return nums->arr[index];\n}\n\n/* \u66f4\u65b0\u5143\u7d20 */\nvoid set(MyList *nums, int index, int num) {\n    assert(index >= 0 && index < nums->size);\n    nums->arr[index] = num;\n}\n\n/* \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20 */\nvoid add(MyList *nums, int num) {\n    if (size(nums) == capacity(nums)) {\n        extendCapacity(nums); // \u6269\u5bb9\n    }\n    nums->arr[size(nums)] = num;\n    nums->size++;\n}\n\n/* \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20 */\nvoid insert(MyList *nums, int index, int num) {\n    assert(index >= 0 && index < size(nums));\n    // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n    if (size(nums) == capacity(nums)) {\n        extendCapacity(nums); // \u6269\u5bb9\n    }\n    for (int i = size(nums); i > index; --i) {\n        nums->arr[i] = nums->arr[i - 1];\n    }\n    nums->arr[index] = num;\n    nums->size++;\n}\n\n/* \u5220\u9664\u5143\u7d20 */\n// \u6ce8\u610f\uff1astdio.h \u5360\u7528\u4e86 remove \u5173\u952e\u8bcd\nint removeItem(MyList *nums, int index) {\n    assert(index >= 0 && index < size(nums));\n    int num = nums->arr[index];\n    for (int i = index; i < size(nums) - 1; i++) {\n        nums->arr[i] = nums->arr[i + 1];\n    }\n    nums->size--;\n    return num;\n}\n\n/* \u5217\u8868\u6269\u5bb9 */\nvoid extendCapacity(MyList *nums) {\n    // \u5148\u5206\u914d\u7a7a\u95f4\n    int newCapacity = capacity(nums) * nums->extendRatio;\n    int *extend = (int *)malloc(sizeof(int) * newCapacity);\n    int *temp = nums->arr;\n\n    // \u62f7\u8d1d\u65e7\u6570\u636e\u5230\u65b0\u6570\u636e\n    for (int i = 0; i < size(nums); i++)\n        extend[i] = nums->arr[i];\n\n    // \u91ca\u653e\u65e7\u6570\u636e\n    free(temp);\n\n    // \u66f4\u65b0\u65b0\u6570\u636e\n    nums->arr = extend;\n    nums->capacity = newCapacity;\n}\n\n/* \u5c06\u5217\u8868\u8f6c\u6362\u4e3a Array \u7528\u4e8e\u6253\u5370 */\nint *toArray(MyList *nums) {\n    return nums->arr;\n}\n
    my_list.zig
    // \u5217\u8868\u7c7b\nfn MyList(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        arr: []T = undefined,                        // \u6570\u7ec4\uff08\u5b58\u50a8\u5217\u8868\u5143\u7d20\uff09\n        arrCapacity: usize = 10,                     // \u5217\u8868\u5bb9\u91cf\n        numSize: usize = 0,                           // \u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n        extendRatio: usize = 2,                       // \u6bcf\u6b21\u5217\u8868\u6269\u5bb9\u7684\u500d\u6570\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined, // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u5217\u8868\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.arr = try self.mem_allocator.alloc(T, self.arrCapacity);\n            @memset(self.arr, @as(T, 0));\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u5217\u8868\u957f\u5ea6\uff08\u5f53\u524d\u5143\u7d20\u6570\u91cf\uff09\n        pub fn size(self: *Self) usize {\n            return self.numSize;\n        }\n\n        // \u83b7\u53d6\u5217\u8868\u5bb9\u91cf\n        pub fn capacity(self: *Self) usize {\n            return self.arrCapacity;\n        }\n\n        // \u8bbf\u95ee\u5143\u7d20\n        pub fn get(self: *Self, index: usize) T {\n            // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n            if (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n            return self.arr[index];\n        }  \n\n        // \u66f4\u65b0\u5143\u7d20\n        pub fn set(self: *Self, index: usize, num: T) void {\n            // \u7d22\u5f15\u5982\u679c\u8d8a\u754c\uff0c\u5219\u629b\u51fa\u5f02\u5e38\uff0c\u4e0b\u540c\n            if (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n            self.arr[index] = num;\n        }  \n\n        // \u5728\u5c3e\u90e8\u6dfb\u52a0\u5143\u7d20\n        pub fn add(self: *Self, num: T) !void {\n            // \u5143\u7d20\u6570\u91cf\u8d85\u51fa\u5bb9\u91cf\u65f6\uff0c\u89e6\u53d1\u6269\u5bb9\u673a\u5236\n            if (self.size() == self.capacity()) try self.extendCapacity();\n            self.arr[self.size()] = num;\n            // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n            self.numSize += 1;\n        }  \n\n        // \u5728\u4e2d\u95f4\u63d2\u5165\u5143\u7d20\n        pub fn insert(self: *Self, index: usize, num: T) !void {\n            if (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\n            if (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\n            var j = self.size() - 1;\n            while (j >= index) : (j -= 1) {\n                self.arr[j + 1] = self.arr[j];\n            }\n            self.arr[index] = num;\n            // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n            self.numSize += 1;\n        }\n\n        // \u5220\u9664\u5143\u7d20\n        pub fn remove(self: *Self, index: usize) T {\n            if (index < 0 or index >= self.size()) @panic(\"\u7d22\u5f15\u8d8a\u754c\");\n            var num = self.arr[index];\n            // \u7d22\u5f15 i \u4e4b\u540e\u7684\u5143\u7d20\u90fd\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\n            var j = index;\n            while (j < self.size() - 1) : (j += 1) {\n                self.arr[j] = self.arr[j + 1];\n            }\n            // \u66f4\u65b0\u5143\u7d20\u6570\u91cf\n            self.numSize -= 1;\n            // \u8fd4\u56de\u88ab\u5220\u9664\u7684\u5143\u7d20\n            return num;\n        }\n\n        // \u5217\u8868\u6269\u5bb9\n        pub fn extendCapacity(self: *Self) !void {\n            // \u65b0\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a size * extendRatio \u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u539f\u6570\u7ec4\u590d\u5236\u5230\u65b0\u6570\u7ec4\n            var newCapacity = self.capacity() * self.extendRatio;\n            var 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\n            std.mem.copy(T, extend, self.arr);\n            self.arr = extend;\n            // \u66f4\u65b0\u5217\u8868\u5bb9\u91cf\n            self.arrCapacity = newCapacity;\n        }\n\n        // \u5c06\u5217\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n            var arr = try self.mem_allocator.alloc(T, self.size());\n           @memset(arr, @as(T, 0));\n            for (arr, 0..) |*num, i| {\n                num.* = self.get(i);\n            }\n            return 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\u4e24\u79cd\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\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\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\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\u4e09\u8005\u5171\u540c\u534f\u4f5c\uff0c\u786e\u4fdd\u8ba1\u7b97\u673a\u7cfb\u7edf\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 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\u5404\u81ea\u5177\u6709\u4f18\u52bf\u548c\u5c40\u9650\u6027\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\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\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\u53ea\u80fd\u5b58\u50a8\u4e00\u5c0f\u90e8\u5206\u9891\u7e41\u8bbf\u95ee\u7684\u6570\u636e\uff0c\u56e0\u6b64\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\u7684\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\u8fd1\u671f\u4e5f\u4f1a\u88ab\u8bbf\u95ee\u3002\u56e0\u6b64\uff0c\u7f13\u5b58\u5728\u52a0\u8f7d\u67d0\u4e00\u6570\u636e\u65f6\uff0c\u4e5f\u4f1a\u52a0\u8f7d\u5176\u9644\u8fd1\u7684\u6570\u636e\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\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\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\u9644\u8fd1\u7684\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\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\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\u5b83\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\u53ef\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\u5c40\u90e8\u6027\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\u57fa\u672c\u4e00\u81f4\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 \u5b57\u8282 \u548c 8 \u5b57\u8282 \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\u201c\u5143\u7d20\u957f\u5ea6\u201d\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 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\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\"\"\"\n    if root is None:\n        return\n    if root.val == 7:\n        # \u8bb0\u5f55\u89e3\n        res.append(root)\n    pre_order(root.left)\n    pre_order(root.right)\n
    preorder_traversal_i_compact.cpp
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode *root) {\n    if (root == nullptr) {\n        return;\n    }\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push_back(root);\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n}\n
    preorder_traversal_i_compact.java
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid preOrder(TreeNode root) {\n    if (root == null) {\n        return;\n    }\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.add(root);\n    }\n    preOrder(root.left);\n    preOrder(root.right);\n}\n
    preorder_traversal_i_compact.cs
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nvoid PreOrder(TreeNode? root) {\n    if (root == null) {\n        return;\n    }\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.Add(root);\n    }\n    PreOrder(root.left);\n    PreOrder(root.right);\n}\n
    preorder_traversal_i_compact.go
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrderI(root *TreeNode, res *[]*TreeNode) {\n    if root == nil {\n        return\n    }\n    if (root.Val).(int) == 7 {\n        // \u8bb0\u5f55\u89e3\n        *res = append(*res, root)\n    }\n    preOrderI(root.Left, res)\n    preOrderI(root.Right, res)\n}\n
    preorder_traversal_i_compact.swift
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunc preOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    if root.val == 7 {\n        // \u8bb0\u5f55\u89e3\n        res.append(root)\n    }\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n}\n
    preorder_traversal_i_compact.js
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e00 */\nfunction preOrder(root, res) {\n    if (root === null) {\n        return;\n    }\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push(root);\n    }\n    preOrder(root.left, res);\n    preOrder(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 {\n    if (root === null) {\n        return;\n    }\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push(root);\n    }\n    preOrder(root.left, res);\n    preOrder(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) {\n  if (root == null) {\n    return;\n  }\n  if (root.val == 7) {\n    // \u8bb0\u5f55\u89e3\n    res.add(root);\n  }\n  preOrder(root.left, res);\n  preOrder(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>>>) {\n    if root.is_none() {\n        return;\n    }\n    if let Some(node) = root {\n        if node.borrow().val == 7 {\n            // \u8bb0\u5f55\u89e3\n            res.push(node.clone());\n        }\n        pre_order(res, node.borrow().left.clone());\n        pre_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) {\n    if (root == NULL) {\n        return;\n    }\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res[resSize++] = root;\n    }\n    preOrder(root->left);\n    preOrder(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\"\"\"\n    if root is None:\n        return\n    # \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7:\n        # \u8bb0\u5f55\u89e3\n        res.append(list(path))\n    pre_order(root.left)\n    pre_order(root.right)\n    # \u56de\u9000\n    path.pop()\n
    preorder_traversal_ii_compact.cpp
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\n    if (root == nullptr) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push_back(root);\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push_back(path);\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    path.pop_back();\n}\n
    preorder_traversal_ii_compact.java
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode root) {\n    if (root == null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.add(new ArrayList<>(path));\n    }\n    preOrder(root.left);\n    preOrder(root.right);\n    // \u56de\u9000\n    path.remove(path.size() - 1);\n}\n
    preorder_traversal_ii_compact.cs
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid PreOrder(TreeNode? root) {\n    if (root == null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.Add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.Add(new List<TreeNode>(path));\n    }\n    PreOrder(root.left);\n    PreOrder(root.right);\n    // \u56de\u9000\n    path.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) {\n    if root == nil {\n        return\n    }\n    // \u5c1d\u8bd5\n    *path = append(*path, root)\n    if root.Val.(int) == 7 {\n        // \u8bb0\u5f55\u89e3\n        *res = append(*res, append([]*TreeNode{}, *path...))\n    }\n    preOrderII(root.Left, res, path)\n    preOrderII(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?) {\n    guard let root = root else {\n        return\n    }\n    // \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7 {\n        // \u8bb0\u5f55\u89e3\n        res.append(path)\n    }\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n    // \u56de\u9000\n    path.removeLast()\n}\n
    preorder_traversal_ii_compact.js
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(root, path, res) {\n    if (root === null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_ii_compact.ts
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nfunction preOrder(\n    root: TreeNode | null,\n    path: TreeNode[],\n    res: TreeNode[][]\n): void {\n    if (root === null) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_ii_compact.dart
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(\n  TreeNode? root,\n  List<TreeNode> path,\n  List<List<TreeNode>> res,\n) {\n  if (root == null) {\n    return;\n  }\n\n  // \u5c1d\u8bd5\n  path.add(root);\n  if (root.val == 7) {\n    // \u8bb0\u5f55\u89e3\n    res.add(List.from(path));\n  }\n  preOrder(root.left, path, res);\n  preOrder(root.right, path, res);\n  // \u56de\u9000\n  path.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>>>) {\n    if root.is_none() {\n        return;\n    }\n    if let Some(node) = root {\n        // \u5c1d\u8bd5\n        path.push(node.clone());\n        if node.borrow().val == 7 {\n            // \u8bb0\u5f55\u89e3\n            res.push(path.clone());\n        }\n        pre_order(res, path, node.borrow().left.clone());\n        pre_order(res, path, node.borrow().right.clone());\n        // \u56de\u9000\n        path.remove(path.len() -  1);\n    }\n}\n
    preorder_traversal_ii_compact.c
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e8c */\nvoid preOrder(TreeNode *root) {\n    if (root == NULL) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path[pathSize++] = root;\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        for (int i = 0; i < pathSize; ++i) {\n            res[resSize][i] = path[i];\n        }\n        resSize++;\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    pathSize--;\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\n    if root is None or root.val == 3:\n        return\n    # \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7:\n        # \u8bb0\u5f55\u89e3\n        res.append(list(path))\n    pre_order(root.left)\n    pre_order(root.right)\n    # \u56de\u9000\n    path.pop()\n
    preorder_traversal_iii_compact.cpp
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode *root) {\n    // \u526a\u679d\n    if (root == nullptr || root->val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push_back(root);\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push_back(path);\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    path.pop_back();\n}\n
    preorder_traversal_iii_compact.java
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(TreeNode root) {\n    // \u526a\u679d\n    if (root == null || root.val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.add(new ArrayList<>(path));\n    }\n    preOrder(root.left);\n    preOrder(root.right);\n    // \u56de\u9000\n    path.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\n    if (root == null || root.val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.Add(root);\n    if (root.val == 7) {\n        // \u8bb0\u5f55\u89e3\n        res.Add(new List<TreeNode>(path));\n    }\n    PreOrder(root.left);\n    PreOrder(root.right);\n    // \u56de\u9000\n    path.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\n    if root == nil || root.Val == 3 {\n        return\n    }\n    // \u5c1d\u8bd5\n    *path = append(*path, root)\n    if root.Val.(int) == 7 {\n        // \u8bb0\u5f55\u89e3\n        *res = append(*res, *path)\n    }\n    preOrderIII(root.Left, res, path)\n    preOrderIII(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\n    guard let root = root, root.val != 3 else {\n        return\n    }\n    // \u5c1d\u8bd5\n    path.append(root)\n    if root.val == 7 {\n        // \u8bb0\u5f55\u89e3\n        res.append(path)\n    }\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n    // \u56de\u9000\n    path.removeLast()\n}\n
    preorder_traversal_iii_compact.js
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(root, path, res) {\n    // \u526a\u679d\n    if (root === null || root.val === 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_iii_compact.ts
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nfunction preOrder(\n    root: TreeNode | null,\n    path: TreeNode[],\n    res: TreeNode[][]\n): void {\n    // \u526a\u679d\n    if (root === null || root.val === 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path.push(root);\n    if (root.val === 7) {\n        // \u8bb0\u5f55\u89e3\n        res.push([...path]);\n    }\n    preOrder(root.left, path, res);\n    preOrder(root.right, path, res);\n    // \u56de\u9000\n    path.pop();\n}\n
    preorder_traversal_iii_compact.dart
    /* \u524d\u5e8f\u904d\u5386\uff1a\u4f8b\u9898\u4e09 */\nvoid preOrder(\n  TreeNode? root,\n  List<TreeNode> path,\n  List<List<TreeNode>> res,\n) {\n  if (root == null || root.val == 3) {\n    return;\n  }\n\n  // \u5c1d\u8bd5\n  path.add(root);\n  if (root.val == 7) {\n    // \u8bb0\u5f55\u89e3\n    res.add(List.from(path));\n  }\n  preOrder(root.left, path, res);\n  preOrder(root.right, path, res);\n  // \u56de\u9000\n  path.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\n    if root.is_none() || root.as_ref().unwrap().borrow().val == 3 {\n        return;\n    }\n    if let Some(node) = root {\n        // \u5c1d\u8bd5\n        path.push(node.clone());\n        if node.borrow().val == 7 {\n            // \u8bb0\u5f55\u89e3\n            res.push(path.clone());\n        }\n        pre_order(res, path, node.borrow().left.clone());\n        pre_order(res, path, node.borrow().right.clone());\n        // \u56de\u9000\n        path.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\n    if (root == NULL || root->val == 3) {\n        return;\n    }\n    // \u5c1d\u8bd5\n    path[pathSize++] = root;\n    if (root->val == 7) {\n        // \u8bb0\u5f55\u89e3\n        for (int i = 0; i < pathSize; i++) {\n            res[resSize][i] = path[i];\n        }\n        resSize++;\n    }\n    preOrder(root->left);\n    preOrder(root->right);\n    // \u56de\u9000\n    pathSize--;\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\n    if is_solution(state):\n        # \u8bb0\u5f55\u89e3\n        record_solution(state, res)\n        # \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices:\n        # \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice):\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice)\n            backtrack(state, choices, res)\n            # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undo_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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (Choice choice : choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (Choice choice : choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (IsSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        RecordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    foreach (Choice choice in choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (IsValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            MakeChoice(state, choice);\n            Backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            UndoChoice(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\n    if isSolution(state) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res)\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for _, choice := range choices {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state, choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice)\n            backtrack(state, choices, res)\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if isSolution(state: state) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state: state, res: &res)\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state: state, choice: choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state: &state, choice: choice)\n            backtrack(state: &state, choices: choices, res: &res)\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (let choice of choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (let choice of choices) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n  if (isSolution(state)) {\n    // \u8bb0\u5f55\u89e3\n    recordSolution(state, res);\n    // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (Choice choice in choices) {\n    // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n    if (isValid(state, choice)) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      makeChoice(state, choice);\n      backtrack(state, choices, res);\n      // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n      undoChoice(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\n    if is_solution(state) {\n        // \u8bb0\u5f55\u89e3\n        record_solution(state, res);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice);\n            backtrack(state, choices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undo_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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res, numRes);\n        // \u4e0d\u518d\u7ee7\u7eed\u641c\u7d22\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < numChoices; i++) {\n        // \u526a\u679d\uff1a\u5224\u65ad\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, &choices[i])) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, &choices[i]);\n            backtrack(state, choices, numChoices, res, numRes);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\"\"\"\n    return state and state[-1].val == 7\n\ndef record_solution(state: list[TreeNode], res: list[list[TreeNode]]):\n    \"\"\"\u8bb0\u5f55\u89e3\"\"\"\n    res.append(list(state))\n\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\"\"\"\n    return choice is not None and choice.val != 3\n\ndef make_choice(state: list[TreeNode], choice: TreeNode):\n    \"\"\"\u66f4\u65b0\u72b6\u6001\"\"\"\n    state.append(choice)\n\ndef undo_choice(state: list[TreeNode], choice: TreeNode):\n    \"\"\"\u6062\u590d\u72b6\u6001\"\"\"\n    state.pop()\n\ndef backtrack(\n    state: 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\n    if is_solution(state):\n        # \u8bb0\u5f55\u89e3\n        record_solution(state, res)\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices:\n        # \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice):\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice)\n            # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state, [choice.left, choice.right], res)\n            # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undo_choice(state, choice)\n
    preorder_traversal_iii_template.cpp
    /* \u5224\u65ad\u5f53\u524d\u72b6\u6001\u662f\u5426\u4e3a\u89e3 */\nbool isSolution(vector<TreeNode *> &state) {\n    return !state.empty() && state.back()->val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(vector<TreeNode *> &state, vector<vector<TreeNode *>> &res) {\n    res.push_back(state);\n}\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) {\n    return choice != nullptr && choice->val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(vector<TreeNode *> &state, TreeNode *choice) {\n    state.push_back(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(vector<TreeNode *> &state, TreeNode *choice) {\n    state.pop_back();\n}\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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (TreeNode *choice : choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            vector<TreeNode *> nextChoices{choice->left, choice->right};\n            backtrack(state, nextChoices, res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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) {\n    return !state.isEmpty() && state.get(state.size() - 1).val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\n    res.add(new ArrayList<>(state));\n}\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) {\n    return choice != null && choice.val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode choice) {\n    state.add(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode choice) {\n    state.remove(state.size() - 1);\n}\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\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (TreeNode choice : choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            undoChoice(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) {\n    return state.Count != 0 && state[^1].val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid RecordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\n    res.Add(new List<TreeNode>(state));\n}\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) {\n    return choice != null && choice.val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid MakeChoice(List<TreeNode> state, TreeNode choice) {\n    state.Add(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid UndoChoice(List<TreeNode> state, TreeNode choice) {\n    state.RemoveAt(state.Count - 1);\n}\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\n    if (IsSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        RecordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    foreach (TreeNode choice in choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (IsValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            MakeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            Backtrack(state, [choice.left!, choice.right!], res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            UndoChoice(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 {\n    return len(*state) != 0 && (*state)[len(*state)-1].Val == 7\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state *[]*TreeNode, res *[][]*TreeNode) {\n    *res = append(*res, *state)\n}\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 {\n    return choice != nil && choice.Val != 3\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state *[]*TreeNode, choice *TreeNode) {\n    *state = append(*state, choice)\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state *[]*TreeNode, choice *TreeNode) {\n    *state = (*state)[:len(*state)-1]\n}\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\n    if isSolution(state) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for _, choice := range *choices {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state, choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            temp := make([]*TreeNode, 0)\n            temp = append(temp, choice.Left, choice.Right)\n            backtrackIII(state, &temp, res)\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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\n/* \u8bb0\u5f55\u89e3 */\nfunc recordSolution(state: [TreeNode], res: inout [[TreeNode]]) {\n    res.append(state)\n}\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 {\n    choice != nil && choice!.val != 3\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunc makeChoice(state: inout [TreeNode], choice: TreeNode) {\n    state.append(choice)\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunc undoChoice(state: inout [TreeNode], choice: TreeNode) {\n    state.removeLast()\n}\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\n    if isSolution(state: state) {\n        recordSolution(state: state, res: &res)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if isValid(state: state, choice: choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state: &state, choice: choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            undoChoice(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) {\n    return state && state[state.length - 1]?.val === 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state, res) {\n    res.push([...state]);\n}\n\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nfunction isValid(state, choice) {\n    return choice !== null && choice.val !== 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state, choice) {\n    state.push(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state) {\n    state.pop();\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(state, choices, res) {\n    // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state, [choice.left, choice.right], res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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 {\n    return state && state[state.length - 1]?.val === 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfunction recordSolution(state: TreeNode[], res: TreeNode[][]): void {\n    res.push([...state]);\n}\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 {\n    return choice !== null && choice.val !== 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfunction makeChoice(state: TreeNode[], choice: TreeNode): void {\n    state.push(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfunction undoChoice(state: TreeNode[]): void {\n    state.pop();\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nfunction backtrack(\n    state: TreeNode[],\n    choices: TreeNode[],\n    res: TreeNode[][]\n): void {\n    // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n    if (isSolution(state)) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(state, choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(state, choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state, [choice.left, choice.right], res);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice(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) {\n  return state.isNotEmpty && state.last.val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {\n  res.add(List.from(state));\n}\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) {\n  return choice != null && choice.val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(List<TreeNode> state, TreeNode? choice) {\n  state.add(choice!);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(List<TreeNode> state, TreeNode? choice) {\n  state.removeLast();\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(\n  List<TreeNode> state,\n  List<TreeNode?> choices,\n  List<List<TreeNode>> res,\n) {\n  // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n  if (isSolution(state)) {\n    // \u8bb0\u5f55\u89e3\n    recordSolution(state, res);\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (TreeNode? choice in choices) {\n    // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n    if (isValid(state, choice)) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      makeChoice(state, choice);\n      // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n      backtrack(state, [choice!.left, choice.right], res);\n      // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n      undoChoice(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 {\n    return !state.is_empty() && state.get(state.len() - 1).unwrap().borrow().val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nfn record_solution(state: &mut Vec<Rc<RefCell<TreeNode>>>, res: &mut Vec<Vec<Rc<RefCell<TreeNode>>>>) {\n    res.push(state.clone());\n}\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 {\n    return choice.borrow().val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nfn make_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, choice: Rc<RefCell<TreeNode>>) {\n    state.push(choice);\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nfn undo_choice(state: &mut Vec<Rc<RefCell<TreeNode>>>, _: Rc<RefCell<TreeNode>>) {\n    state.remove(state.len() - 1);\n}\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\n    if is_solution(state) {\n        // \u8bb0\u5f55\u89e3\n        record_solution(state, res);\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if is_valid(state, choice.clone()) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            make_choice(state, choice.clone());\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            undo_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) {\n    return pathSize > 0 && path[pathSize - 1]->val == 7;\n}\n\n/* \u8bb0\u5f55\u89e3 */\nvoid recordSolution(void) {\n    for (int i = 0; i < pathSize; i++) {\n        res[resSize][i] = path[i];\n    }\n    resSize++;\n}\n\n/* \u5224\u65ad\u5728\u5f53\u524d\u72b6\u6001\u4e0b\uff0c\u8be5\u9009\u62e9\u662f\u5426\u5408\u6cd5 */\nbool isValid(TreeNode *choice) {\n    return choice != NULL && choice->val != 3;\n}\n\n/* \u66f4\u65b0\u72b6\u6001 */\nvoid makeChoice(TreeNode *choice) {\n    path[pathSize++] = choice;\n}\n\n/* \u6062\u590d\u72b6\u6001 */\nvoid undoChoice(void) {\n    pathSize--;\n}\n\n/* \u56de\u6eaf\u7b97\u6cd5\uff1a\u4f8b\u9898\u4e09 */\nvoid backtrack(TreeNode *choices[2]) {\n    // \u68c0\u67e5\u662f\u5426\u4e3a\u89e3\n    if (isSolution()) {\n        // \u8bb0\u5f55\u89e3\n        recordSolution();\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < 2; i++) {\n        TreeNode *choice = choices[i];\n        // \u526a\u679d\uff1a\u68c0\u67e5\u9009\u62e9\u662f\u5426\u5408\u6cd5\n        if (isValid(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            makeChoice(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            TreeNode *nextChoices[2] = {choice->left, choice->right};\n            backtrack(nextChoices);\n            // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n            undoChoice();\n        }\n    }\n}\n
    preorder_traversal_iii_template.zig
    [class]{}-[func]{isSolution}\n\n[class]{}-[func]{recordSolution}\n\n[class]{}-[func]{isValid}\n\n[class]{}-[func]{makeChoice}\n\n[class]{}-[func]{undoChoice}\n\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\u6761\u5bf9\u89d2\u7ebf\u4e0a\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(\n    row: int,\n    n: int,\n    state: list[list[str]],\n    res: list[list[list[str]]],\n    cols: list[bool],\n    diags1: list[bool],\n    diags2: list[bool],\n):\n    \"\"\"\u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e\"\"\"\n    # \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if row == n:\n        res.append([list(row) for row in state])\n        return\n    # \u904d\u5386\u6240\u6709\u5217\n    for col in range(n):\n        # \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        diag1 = row - col + n - 1\n        diag2 = row + col\n        # \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if not cols[col] and not diags1[diag1] and not 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\n            # \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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\n\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\n    state = [[\"#\" for _ in range(n)] for _ in range(n)]\n    cols = [False] * n  # \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    diags1 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    diags2 = [False] * (2 * n - 1)  # \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    res = []\n    backtrack(0, n, state, res, cols, diags1, diags2)\n\n    return 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,\n               vector<bool> &diags1, vector<bool> &diags2) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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;\n        }\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\n    vector<vector<string>> state(n, vector<string>(n, \"#\"));\n    vector<bool> cols(n, false);           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    vector<bool> diags1(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    vector<bool> diags2(2 * n - 1, false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    vector<vector<vector<string>>> res;\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n\n    return 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,\n        boolean[] cols, boolean[] diags1, boolean[] diags2) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        List<List<String>> copyState = new ArrayList<>();\n        for (List<String> sRow : state) {\n            copyState.add(new ArrayList<>(sRow));\n        }\n        res.add(copyState);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!cols[col] && !diags1[diag1] && !diags2[diag2]) {\n            // \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n            state.get(row).set(col, \"Q\");\n            cols[col] = diags1[diag1] = diags2[diag2] = true;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(row + 1, n, state, res, cols, diags1, diags2);\n            // \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n            state.get(row).set(col, \"#\");\n            cols[col] = diags1[diag1] = diags2[diag2] = false;\n        }\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\n    List<List<String>> state = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n        List<String> row = new ArrayList<>();\n        for (int j = 0; j < n; j++) {\n            row.add(\"#\");\n        }\n        state.add(row);\n    }\n    boolean[] cols = new boolean[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    boolean[] diags1 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    boolean[] diags2 = new boolean[2 * n - 1]; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    List<List<List<String>>> res = new ArrayList<>();\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n\n    return 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,\n        bool[] cols, bool[] diags1, bool[] diags2) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        List<List<string>> copyState = [];\n        foreach (List<string> sRow in state) {\n            copyState.Add(new List<string>(sRow));\n        }\n        res.Add(copyState);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            Backtrack(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;\n        }\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\n    List<List<string>> state = [];\n    for (int i = 0; i < n; i++) {\n        List<string> row = [];\n        for (int j = 0; j < n; j++) {\n            row.Add(\"#\");\n        }\n        state.Add(row);\n    }\n    bool[] cols = new bool[n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    bool[] diags1 = new bool[2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    bool[] diags2 = new bool[2 * n - 1]; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    List<List<List<string>>> res = [];\n\n    Backtrack(0, n, state, res, cols, diags1, diags2);\n\n    return 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\n    if row == n {\n        newState := make([][]string, len(*state))\n        for i, _ := range newState {\n            newState[i] = make([]string, len((*state)[0]))\n            copy(newState[i], (*state)[i])\n\n        }\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col := 0; col < n; col++ {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        diag1 := row - col + n - 1\n        diag2 := row + col\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !(*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\n            backtrack(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\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\n    if row == n {\n        newState := make([][]string, len(*state))\n        for i, _ := range newState {\n            newState[i] = make([]string, len((*state)[0]))\n            copy(newState[i], (*state)[i])\n\n        }\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col := 0; col < n; col++ {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        diag1 := row - col + n - 1\n        diag2 := row + col\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !(*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\n            backtrack(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\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\n    state := make([][]string, n)\n    for i := 0; i < n; i++ {\n        row := make([]string, n)\n        for i := 0; i < n; i++ {\n            row[i] = \"#\"\n        }\n        state[i] = row\n    }\n    // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    cols := make([]bool, n)\n    diags1 := make([]bool, 2*n-1)\n    diags2 := make([]bool, 2*n-1)\n    res := make([][][]string, 0)\n    backtrack(0, n, &state, &res, &cols, &diags1, &diags2)\n    return 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\n    if row == n {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col in 0 ..< n {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        let diag1 = row - col + n - 1\n        let diag2 = row + col\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !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] = true\n            diags1[diag1] = true\n            diags2[diag2] = true\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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\n            state[row][col] = \"#\"\n            cols[col] = false\n            diags1[diag1] = false\n            diags2[diag2] = false\n        }\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\n    var state = Array(repeating: Array(repeating: \"#\", count: n), count: n)\n    var cols = Array(repeating: false, count: n) // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    var diags1 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    var diags2 = Array(repeating: false, count: 2 * n - 1) // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    var res: [[[String]]] = []\n\n    backtrack(row: 0, n: n, state: &state, res: &res, cols: &cols, diags1: &diags1, diags2: &diags2)\n\n    return 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\n    if (row === n) {\n        res.push(state.map((row) => row.slice()));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (let col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        const diag1 = row - col + n - 1;\n        const diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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;\n        }\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\n    const state = Array.from({ length: n }, () => Array(n).fill('#'));\n    const cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    const diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const res = [];\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n    return res;\n}\n
    n_queens.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nfunction backtrack(\n    row: number,\n    n: number,\n    state: string[][],\n    res: string[][][],\n    cols: boolean[],\n    diags1: boolean[],\n    diags2: boolean[]\n): void {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row === n) {\n        res.push(state.map((row) => row.slice()));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (let col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        const diag1 = row - col + n - 1;\n        const diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(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;\n        }\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\n    const state = Array.from({ length: n }, () => Array(n).fill('#'));\n    const cols = Array(n).fill(false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    const diags1 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const diags2 = Array(2 * n - 1).fill(false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    const res: string[][][] = [];\n\n    backtrack(0, n, state, res, cols, diags1, diags2);\n    return res;\n}\n
    n_queens.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1aN \u7687\u540e */\nvoid backtrack(\n  int row,\n  int n,\n  List<List<String>> state,\n  List<List<List<String>>> res,\n  List<bool> cols,\n  List<bool> diags1,\n  List<bool> diags2,\n) {\n  // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (row == n) {\n    List<List<String>> copyState = [];\n    for (List<String> sRow in state) {\n      copyState.add(List.from(sRow));\n    }\n    res.add(copyState);\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u5217\n  for (int col = 0; col < n; col++) {\n    // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n    int diag1 = row - col + n - 1;\n    int diag2 = row + col;\n    // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n    if (!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] = true;\n      diags1[diag1] = true;\n      diags2[diag2] = true;\n      // \u653e\u7f6e\u4e0b\u4e00\u884c\n      backtrack(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] = false;\n      diags1[diag1] = false;\n      diags2[diag2] = false;\n    }\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\n  List<List<String>> state = List.generate(n, (index) => List.filled(n, \"#\"));\n  List<bool> cols = List.filled(n, false); // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n  List<bool> diags1 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n  List<bool> diags2 = List.filled(2 * n - 1, false); // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n  List<List<List<String>>> res = [];\n\n  backtrack(0, n, state, res, cols, diags1, diags2);\n\n  return 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>>>,\n    cols: &mut [bool], diags1: &mut [bool], diags2: &mut [bool]) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if row == n {\n        let mut copy_state: Vec<Vec<String>> = Vec::new();\n        for s_row in state.clone() {\n            copy_state.push(s_row);\n        }\n        res.push(copy_state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for col in 0..n {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        let diag1 = row + n - 1 - col;\n        let diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if !cols[col] && !diags1[diag1] && !diags2[diag2] {\n            // \u5c1d\u8bd5\uff1a\u5c06\u7687\u540e\u653e\u7f6e\u5728\u8be5\u683c\u5b50\n            state.get_mut(row).unwrap()[col] = \"Q\".into();\n            (cols[col], diags1[diag1], diags2[diag2]) = (true, true, true);\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(row + 1, n, state, res, cols, diags1, diags2);\n            // \u56de\u9000\uff1a\u5c06\u8be5\u683c\u5b50\u6062\u590d\u4e3a\u7a7a\u4f4d\n            state.get_mut(row).unwrap()[col] = \"#\".into();\n            (cols[col], diags1[diag1], diags2[diag2]) = (false, false, false);\n        }\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\n    let mut state: Vec<Vec<String>> = Vec::new();\n    for _ in 0..n {\n        let mut row: Vec<String> = Vec::new();\n        for _ in 0..n {\n            row.push(\"#\".into());\n        }\n        state.push(row);\n    }\n    let mut cols = vec![false; n]; // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    let mut diags1 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    let mut diags2 = vec![false; 2 * n - 1]; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    let mut res: Vec<Vec<Vec<String>>> = Vec::new();\n\n    backtrack(0, n, &mut state, &mut res, &mut cols, &mut diags1, &mut diags2);\n\n    res\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],\n               bool diags1[2 * MAX_SIZE - 1], bool diags2[2 * MAX_SIZE - 1]) {\n    // \u5f53\u653e\u7f6e\u5b8c\u6240\u6709\u884c\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (row == n) {\n        res[*resSize] = (char **)malloc(sizeof(char *) * n);\n        for (int i = 0; i < n; ++i) {\n            res[*resSize][i] = (char *)malloc(sizeof(char) * (n + 1));\n            strcpy(res[*resSize][i], state[i]);\n        }\n        (*resSize)++;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u5217\n    for (int col = 0; col < n; col++) {\n        // \u8ba1\u7b97\u8be5\u683c\u5b50\u5bf9\u5e94\u7684\u4e3b\u5bf9\u89d2\u7ebf\u548c\u6b21\u5bf9\u89d2\u7ebf\n        int diag1 = row - col + n - 1;\n        int diag2 = row + col;\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8be5\u683c\u5b50\u6240\u5728\u5217\u3001\u4e3b\u5bf9\u89d2\u7ebf\u3001\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u5b58\u5728\u7687\u540e\n        if (!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;\n            // \u653e\u7f6e\u4e0b\u4e00\u884c\n            backtrack(row + 1, n, state, res, resSize, 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;\n        }\n    }\n}\n\n/* \u6c42\u89e3 N \u7687\u540e */\nchar ***nQueens(int n, int *returnSize) {\n    char 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\n    for (int i = 0; i < n; ++i) {\n        for (int j = 0; j < n; ++j) {\n            state[i][j] = '#';\n        }\n        state[i][n] = '\\0';\n    }\n    bool cols[MAX_SIZE] = {false};           // \u8bb0\u5f55\u5217\u662f\u5426\u6709\u7687\u540e\n    bool diags1[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u4e3b\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n    bool diags2[2 * MAX_SIZE - 1] = {false}; // \u8bb0\u5f55\u6b21\u5bf9\u89d2\u7ebf\u4e0a\u662f\u5426\u6709\u7687\u540e\n\n    char ***res = (char ***)malloc(sizeof(char **) * MAX_SIZE);\n    *returnSize = 0;\n    backtrack(0, n, state, res, returnSize, cols, diags1, diags2);\n    return res;\n}\n
    n_queens.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if len(state) == len(choices):\n        res.append(list(state))\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i, choice in enumerate(choices):\n        # \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if not selected[i]:\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = True\n            state.append(choice)\n            # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop()\n\ndef permutations_i(nums: list[int]) -> list[list[int]]:\n    \"\"\"\u5168\u6392\u5217 I\"\"\"\n    res = []\n    backtrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\n    return 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\n    if (state.size() == choices.size()) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choices.size(); i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push_back(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop_back();\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nvector<vector<int>> permutationsI(vector<int> nums) {\n    vector<int> state;\n    vector<bool> selected(nums.size(), false);\n    vector<vector<int>> res;\n    backtrack(state, nums, selected, res);\n    return 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\n    if (state.size() == choices.length) {\n        res.add(new ArrayList<Integer>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choices.length; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.remove(state.size() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nList<List<Integer>> permutationsI(int[] nums) {\n    List<List<Integer>> res = new ArrayList<List<Integer>>();\n    backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\n    return 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\n    if (state.Count == choices.Length) {\n        res.Add(new List<int>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choices.Length; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.Add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            Backtrack(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.RemoveAt(state.Count - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nList<List<int>> PermutationsI(int[] nums) {\n    List<List<int>> res = [];\n    Backtrack([], nums, new bool[nums.Length], res);\n    return 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\n    if len(*state) == len(*choices) {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i := 0; i < len(*choices); i++ {\n        choice := (*choices)[i]\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if !(*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\n            backtrackI(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\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums []int) [][]int {\n    res := make([][]int, 0)\n    state := make([]int, 0)\n    selected := make([]bool, len(nums))\n    backtrackI(&state, &nums, &selected, &res)\n    return 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\n    if state.count == choices.count {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (i, choice) in choices.enumerated() {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if !selected[i] {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true\n            state.append(choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false\n            state.removeLast()\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nfunc permutationsI(nums: [Int]) -> [[Int]] {\n    var state: [Int] = []\n    var selected = Array(repeating: false, count: nums.count)\n    var res: [[Int]] = []\n    backtrack(state: &state, choices: nums, selected: &selected, res: &res)\n    return 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\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    choices.forEach((choice, i) => {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums) {\n    const res = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_i.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nfunction backtrack(\n    state: number[],\n    choices: number[],\n    selected: boolean[],\n    res: number[][]\n): void {\n    // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    choices.forEach((choice, i) => {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 I */\nfunction permutationsI(nums: number[]): number[][] {\n    const res: number[][] = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_i.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 I */\nvoid backtrack(\n  List<int> state,\n  List<int> choices,\n  List<bool> selected,\n  List<List<int>> res,\n) {\n  // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (state.length == choices.length) {\n    res.add(List.from(state));\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (int i = 0; i < choices.length; i++) {\n    int choice = choices[i];\n    // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n    if (!selected[i]) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      selected[i] = true;\n      state.add(choice);\n      // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n      backtrack(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.removeLast();\n    }\n  }\n}\n\n/* \u5168\u6392\u5217 I */\nList<List<int>> permutationsI(List<int> nums) {\n  List<List<int>> res = [];\n  backtrack([], nums, List.filled(nums.length, false), res);\n  return 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\n    if state.len() == choices.len() {\n        res.push(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i in 0..choices.len() {\n        let choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if !selected[i] {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state.clone(), 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.remove(state.len() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nfn permutations_i(nums: &mut [i32]) -> Vec<Vec<i32>> {\n    let mut res = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    backtrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\n    res\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\n    if (stateSize == choicesSize) {\n        res[*resSize] = (int *)malloc(choicesSize * sizeof(int));\n        for (int i = 0; i < choicesSize; i++) {\n            res[*resSize][i] = state[i];\n        }\n        (*resSize)++;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choicesSize; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u91cd\u590d\u9009\u62e9\u5143\u7d20\n        if (!selected[i]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            selected[i] = true;\n            state[stateSize] = choice;\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false;\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 I */\nint **permutationsI(int *nums, int numsSize, int *returnSize) {\n    int *state = (int *)malloc(numsSize * sizeof(int));\n    bool *selected = (bool *)malloc(numsSize * sizeof(bool));\n    for (int i = 0; i < numsSize; i++) {\n        selected[i] = false;\n    }\n    int **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n    *returnSize = 0;\n\n    backtrack(state, 0, nums, numsSize, selected, res, returnSize);\n\n    free(state);\n    free(selected);\n\n    return res;\n}\n
    permutations_i.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if len(state) == len(choices):\n        res.append(list(state))\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    duplicated = set[int]()\n    for 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\n        if not selected[i] and choice not in duplicated:\n            # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice)  # \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = True\n            state.append(choice)\n            # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop()\n\ndef permutations_ii(nums: list[int]) -> list[list[int]]:\n    \"\"\"\u5168\u6392\u5217 II\"\"\"\n    res = []\n    backtrack(state=[], choices=nums, selected=[False] * len(nums), res=res)\n    return 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\n    if (state.size() == choices.size()) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    unordered_set<int> duplicated;\n    for (int i = 0; i < choices.size(); i++) {\n        int 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\n        if (!selected[i] && duplicated.find(choice) == duplicated.end()) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.emplace(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push_back(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop_back();\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nvector<vector<int>> permutationsII(vector<int> nums) {\n    vector<int> state;\n    vector<bool> selected(nums.size(), false);\n    vector<vector<int>> res;\n    backtrack(state, nums, selected, res);\n    return 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\n    if (state.size() == choices.length) {\n        res.add(new ArrayList<Integer>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    Set<Integer> duplicated = new HashSet<Integer>();\n    for (int i = 0; i < choices.length; i++) {\n        int 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\n        if (!selected[i] && !duplicated.contains(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.remove(state.size() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nList<List<Integer>> permutationsII(int[] nums) {\n    List<List<Integer>> res = new ArrayList<List<Integer>>();\n    backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);\n    return 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\n    if (state.Count == choices.Length) {\n        res.Add(new List<int>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    HashSet<int> duplicated = [];\n    for (int i = 0; i < choices.Length; i++) {\n        int 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\n        if (!selected[i] && !duplicated.Contains(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.Add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.Add(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            Backtrack(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.RemoveAt(state.Count - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nList<List<int>> PermutationsII(int[] nums) {\n    List<List<int>> res = [];\n    Backtrack([], nums, new bool[nums.Length], res);\n    return 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\n    if len(*state) == len(*choices) {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    duplicated := make(map[int]struct{}, 0)\n    for i := 0; i < len(*choices); i++ {\n        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\n        if _, 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\n            duplicated[choice] = struct{}{}\n            (*selected)[i] = true\n            *state = append(*state, choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrackI(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\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums []int) [][]int {\n    res := make([][]int, 0)\n    state := make([]int, 0)\n    selected := make([]bool, len(nums))\n    backtrackII(&state, &nums, &selected, &res)\n    return 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\n    if state.count == choices.count {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    var duplicated: Set<Int> = []\n    for (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\n        if !selected[i], !duplicated.contains(choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.insert(choice) // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true\n            state.append(choice)\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false\n            state.removeLast()\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nfunc permutationsII(nums: [Int]) -> [[Int]] {\n    var state: [Int] = []\n    var selected = Array(repeating: false, count: nums.count)\n    var res: [[Int]] = []\n    backtrack(state: &state, choices: nums, selected: &selected, res: &res)\n    return 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\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    const duplicated = new Set();\n    choices.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\n        if (!selected[i] && !duplicated.has(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums) {\n    const res = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_ii.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nfunction backtrack(\n    state: number[],\n    choices: number[],\n    selected: boolean[],\n    res: number[][]\n): void {\n    // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (state.length === choices.length) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    const duplicated = new Set();\n    choices.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\n        if (!selected[i] && !duplicated.has(choice)) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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.pop();\n        }\n    });\n}\n\n/* \u5168\u6392\u5217 II */\nfunction permutationsII(nums: number[]): number[][] {\n    const res: number[][] = [];\n    backtrack([], nums, Array(nums.length).fill(false), res);\n    return res;\n}\n
    permutations_ii.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5168\u6392\u5217 II */\nvoid backtrack(\n  List<int> state,\n  List<int> choices,\n  List<bool> selected,\n  List<List<int>> res,\n) {\n  // \u5f53\u72b6\u6001\u957f\u5ea6\u7b49\u4e8e\u5143\u7d20\u6570\u91cf\u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (state.length == choices.length) {\n    res.add(List.from(state));\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  Set<int> duplicated = {};\n  for (int i = 0; i < choices.length; i++) {\n    int 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\n    if (!selected[i] && !duplicated.contains(choice)) {\n      // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n      duplicated.add(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n      selected[i] = true;\n      state.add(choice);\n      // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n      backtrack(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.removeLast();\n    }\n  }\n}\n\n/* \u5168\u6392\u5217 II */\nList<List<int>> permutationsII(List<int> nums) {\n  List<List<int>> res = [];\n  backtrack([], nums, List.filled(nums.length, false), res);\n  return 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\n    if state.len() == choices.len() {\n        res.push(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    let mut duplicated = HashSet::<i32>::new();\n    for i in 0..choices.len() {\n        let 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\n        if !selected[i] && !duplicated.contains(&choice) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated.insert(choice); // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state.push(choice);\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(state.clone(), 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.remove(state.len() - 1);\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nfn permutations_ii(nums: &mut [i32]) -> Vec<Vec<i32>> {\n    let mut res = Vec::new();\n    backtrack(Vec::new(), nums, &mut vec![false; nums.len()], &mut res);\n    res\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\n    if (stateSize == choicesSize) {\n        res[*resSize] = (int *)malloc(choicesSize * sizeof(int));\n        for (int i = 0; i < choicesSize; i++) {\n            res[*resSize][i] = state[i];\n        }\n        (*resSize)++;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    bool duplicated[MAX_SIZE] = {false};\n    for (int i = 0; i < choicesSize; i++) {\n        int 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\n        if (!selected[i] && !duplicated[choice]) {\n            // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n            duplicated[choice] = true; // \u8bb0\u5f55\u9009\u62e9\u8fc7\u7684\u5143\u7d20\u503c\n            selected[i] = true;\n            state[stateSize] = choice;\n            // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n            backtrack(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\n            selected[i] = false;\n        }\n    }\n}\n\n/* \u5168\u6392\u5217 II */\nint **permutationsII(int *nums, int numsSize, int *returnSize) {\n    int *state = (int *)malloc(numsSize * sizeof(int));\n    bool *selected = (bool *)malloc(numsSize * sizeof(bool));\n    for (int i = 0; i < numsSize; i++) {\n        selected[i] = false;\n    }\n    int **res = (int **)malloc(MAX_SIZE * sizeof(int *));\n    *returnSize = 0;\n\n    backtrack(state, 0, nums, numsSize, selected, res, returnSize);\n\n    free(state);\n    free(selected);\n\n    return res;\n}\n
    permutations_ii.zig
    [class]{}-[func]{backtrack}\n\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\u907f\u514d\u67d0\u4e2a\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\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(\n    state: list[int],\n    target: int,\n    total: int,\n    choices: list[int],\n    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\n    if total == target:\n        res.append(list(state))\n        return\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i in range(len(choices)):\n        # \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if total + choices[i] > target:\n            continue\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.append(choices[i])\n        # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res)\n        # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop()\n\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\"\"\"\n    state = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    total = 0  # \u5b50\u96c6\u548c\n    res = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res)\n    return 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\n    if (total == target) {\n        res.push_back(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push_back(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop_back();\n    }\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) {\n    vector<int> state;       // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    int total = 0;           // \u5b50\u96c6\u548c\n    vector<vector<int>> res; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return 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\n    if (total == target) {\n        res.add(new ArrayList<>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.remove(state.size() - 1);\n    }\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) {\n    List<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    int total = 0; // \u5b50\u96c6\u548c\n    List<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return 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\n    if (total == target) {\n        res.Add(new List<int>(state));\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.Add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        Backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.RemoveAt(state.Count - 1);\n    }\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) {\n    List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    int total = 0; // \u5b50\u96c6\u548c\n    List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    Backtrack(state, target, total, nums, res);\n    return 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\n    if target == total {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i := 0; i < len(*choices); i++ {\n        // \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if total+(*choices)[i] > target {\n            continue\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\n        backtrackSubsetSumINaive(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\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums []int, target int) [][]int {\n    state := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    total := 0              // \u5b50\u96c6\u548c\n    res := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrackSubsetSumINaive(total, target, &state, &nums, &res)\n    return 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\n    if total == target {\n        res.append(state)\n        return\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for 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\n        if total + choices[i] > target {\n            continue\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.append(choices[i])\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.removeLast()\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunc subsetSumINaive(nums: [Int], target: Int) -> [[Int]] {\n    var state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let total = 0 // \u5b50\u96c6\u548c\n    var res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state: &state, target: target, total: total, choices: nums, res: &res)\n    return 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\n    if (total === target) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums, target) {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    const total = 0; // \u5b50\u96c6\u548c\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return res;\n}\n
    subset_sum_i_naive.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\n    state: number[],\n    target: number,\n    total: number,\n    choices: number[],\n    res: number[][]\n): void {\n    // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (total === target) {\n        res.push([...state]);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (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\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target, total + choices[i], choices, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I\uff08\u5305\u542b\u91cd\u590d\u5b50\u96c6\uff09 */\nfunction subsetSumINaive(nums: number[], target: number): number[][] {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    const total = 0; // \u5b50\u96c6\u548c\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, res);\n    return res;\n}\n
    subset_sum_i_naive.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\n  List<int> state,\n  int target,\n  int total,\n  List<int> choices,\n  List<List<int>> res,\n) {\n  // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (total == target) {\n    res.add(List.from(state));\n    return;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (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\n    if (total + choices[i] > target) {\n      continue;\n    }\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n    state.add(choices[i]);\n    // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n    backtrack(state, target, total + choices[i], choices, res);\n    // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n    state.removeLast();\n  }\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) {\n  List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n  int total = 0; // \u5143\u7d20\u548c\n  List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n  backtrack(state, target, total, nums, res);\n  return 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\n    if total == target {\n        res.push(state);\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for i in 0..choices.len() {\n        // \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if total + choices[i] > target {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\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>> {\n    let state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let total = 0; // \u5b50\u96c6\u548c\n    let mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, total, nums, &mut res);\n    res\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\n    if (total == target) {\n        for (int i = 0; i < stateSize; i++) {\n            res[resSize][i] = state[i];\n        }\n        resColSizes[resSize++] = stateSize;\n        return;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < choicesSize; i++) {\n        // \u526a\u679d\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u8df3\u8fc7\u8be5\u9009\u62e9\n        if (total + choices[i] > target) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u5143\u7d20\u548c total\n        state[stateSize++] = choices[i];\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(target, total + choices[i], choices, choicesSize);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        stateSize--;\n    }\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) {\n    resSize = 0; // \u521d\u59cb\u5316\u89e3\u7684\u6570\u91cf\u4e3a0\n    backtrack(target, 0, nums, numsSize);\n}\n
    subset_sum_i_naive.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if target == 0:\n        res.append(list(state))\n        return\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    for 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\n        if target - choices[i] < 0:\n            break\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res)\n        # \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop()\n\ndef subset_sum_i(nums: list[int], target: int) -> list[list[int]]:\n    \"\"\"\u6c42\u89e3\u5b50\u96c6\u548c I\"\"\"\n    state = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start = 0  # \u904d\u5386\u8d77\u59cb\u70b9\n    res = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res)\n    return 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\n    if (target == 0) {\n        res.push_back(state);\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push_back(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop_back();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvector<vector<int>> subsetSumI(vector<int> &nums, int target) {\n    vector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\n    vector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.add(new ArrayList<>(state));\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.remove(state.size() - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<Integer>> subsetSumI(int[] nums, int target) {\n    List<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Arrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.Add(new List<int>(state));\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.Add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        Backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.RemoveAt(state.Count - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> SubsetSumI(int[] nums, int target) {\n    List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Array.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    Backtrack(state, target, nums, start, res);\n    return 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\n    if target == 0 {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n        return\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    for 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\n        if target-(*choices)[i] < 0 {\n            break\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\n        backtrackSubsetSumI(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\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums []int, target int) [][]int {\n    state := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start := 0              // \u904d\u5386\u8d77\u59cb\u70b9\n    res := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrackSubsetSumI(start, target, &state, &nums, &res)\n    return 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\n    if target == 0 {\n        res.append(state)\n        return\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    for 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\n        if target - choices[i] < 0 {\n            break\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.removeLast()\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunc subsetSumI(nums: [Int], target: Int) -> [[Int]] {\n    var state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\n    var res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state: &state, target: target, choices: nums, start: start, res: &res)\n    return 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\n    if (target === 0) {\n        res.push([...state]);\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums, target) {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_i.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nfunction backtrack(\n    state: number[],\n    target: number,\n    choices: number[],\n    start: number,\n    res: number[][]\n): void {\n    // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (target === 0) {\n        res.push([...state]);\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(state, target - choices[i], choices, i, res);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfunction subsetSumI(nums: number[], target: number): number[][] {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_i.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c I */\nvoid backtrack(\n  List<int> state,\n  int target,\n  List<int> choices,\n  int start,\n  List<List<int>> res,\n) {\n  // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (target == 0) {\n    res.add(List.from(state));\n    return;\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  for (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\n    if (target - choices[i] < 0) {\n      break;\n    }\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n    state.add(choices[i]);\n    // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n    backtrack(state, target - choices[i], choices, i, res);\n    // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n    state.removeLast();\n  }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nList<List<int>> subsetSumI(List<int> nums, int target) {\n  List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n  nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n  int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n  List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n  backtrack(state, target, nums, start, res);\n  return 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\n    if target == 0 {\n        res.push(state);\n        return;\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    for 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\n        if target - choices[i] < 0 {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nfn subset_sum_i(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\n    let state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    let mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, &mut res);\n    res\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\n    if (target == 0) {\n        for (int i = 0; i < stateSize; ++i) {\n            res[resSize][i] = state[i];\n        }\n        resColSizes[resSize++] = stateSize;\n        return;\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    for (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\n        if (target - choices[i] < 0) {\n            break;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state[stateSize] = choices[i];\n        stateSize++;\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(target - choices[i], choices, choicesSize, i);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        stateSize--;\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c I */\nvoid subsetSumI(int *nums, int numsSize, int target) {\n    qsort(nums, numsSize, sizeof(int), cmp); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0;                           // \u904d\u5386\u8d77\u59cb\u70b9\n    backtrack(target, nums, numsSize, start);\n}\n
    subset_sum_i.zig
    [class]{}-[func]{backtrack}\n\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(\n    state: 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\n    if target == 0:\n        res.append(list(state))\n        return\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\n    for 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\n        if target - choices[i] < 0:\n            break\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\n        if i > start and choices[i] == choices[i - 1]:\n            continue\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        # \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop()\n\ndef subset_sum_ii(nums: list[int], target: int) -> list[list[int]]:\n    \"\"\"\u6c42\u89e3\u5b50\u96c6\u548c II\"\"\"\n    state = []  # \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort()  # \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start = 0  # \u904d\u5386\u8d77\u59cb\u70b9\n    res = []  # \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res)\n    return 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\n    if (target == 0) {\n        res.push_back(state);\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push_back(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop_back();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvector<vector<int>> subsetSumII(vector<int> &nums, int target) {\n    vector<int> state;              // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort(nums.begin(), nums.end()); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0;                  // \u904d\u5386\u8d77\u59cb\u70b9\n    vector<vector<int>> res;        // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.add(new ArrayList<>(state));\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.remove(state.size() - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<Integer>> subsetSumII(int[] nums, int target) {\n    List<Integer> state = new ArrayList<>(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Arrays.sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<Integer>> res = new ArrayList<>(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return 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\n    if (target == 0) {\n        res.Add(new List<int>(state));\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.Add(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        Backtrack(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\n        state.RemoveAt(state.Count - 1);\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> SubsetSumII(int[] nums, int target) {\n    List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    Array.Sort(nums); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    Backtrack(state, target, nums, start, res);\n    return 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\n    if target == 0 {\n        newState := append([]int{}, *state...)\n        *res = append(*res, newState)\n        return\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\n    for 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\n        if target-(*choices)[i] < 0 {\n            break\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\n        if i > start && (*choices)[i] == (*choices)[i-1] {\n            continue\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\n        backtrackSubsetSumII(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\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums []int, target int) [][]int {\n    state := make([]int, 0) // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    sort.Ints(nums)         // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    start := 0              // \u904d\u5386\u8d77\u59cb\u70b9\n    res := make([][]int, 0) // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrackSubsetSumII(start, target, &state, &nums, &res)\n    return 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\n    if target == 0 {\n        res.append(state)\n        return\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\n    for 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\n        if target - choices[i] < 0 {\n            break\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\n        if i > start, choices[i] == choices[i - 1] {\n            continue\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.append(choices[i])\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.removeLast()\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunc subsetSumII(nums: [Int], target: Int) -> [[Int]] {\n    var state: [Int] = [] // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    let nums = nums.sorted() // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0 // \u904d\u5386\u8d77\u59cb\u70b9\n    var res: [[Int]] = [] // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state: &state, target: target, choices: nums, start: start, res: &res)\n    return 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\n    if (target === 0) {\n        res.push([...state]);\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] === choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums, target) {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_ii.ts
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nfunction backtrack(\n    state: number[],\n    target: number,\n    choices: number[],\n    start: number,\n    res: number[][]\n): void {\n    // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n    if (target === 0) {\n        res.push([...state]);\n        return;\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\n    for (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\n        if (target - choices[i] < 0) {\n            break;\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\n        if (i > start && choices[i] === choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfunction subsetSumII(nums: number[], target: number): number[][] {\n    const state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort((a, b) => a - b); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    const start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    const res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, res);\n    return res;\n}\n
    subset_sum_ii.dart
    /* \u56de\u6eaf\u7b97\u6cd5\uff1a\u5b50\u96c6\u548c II */\nvoid backtrack(\n  List<int> state,\n  int target,\n  List<int> choices,\n  int start,\n  List<List<int>> res,\n) {\n  // \u5b50\u96c6\u548c\u7b49\u4e8e target \u65f6\uff0c\u8bb0\u5f55\u89e3\n  if (target == 0) {\n    res.add(List.from(state));\n    return;\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\n  for (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\n    if (target - choices[i] < 0) {\n      break;\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\n    if (i > start && choices[i] == choices[i - 1]) {\n      continue;\n    }\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n    state.add(choices[i]);\n    // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n    backtrack(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\n    state.removeLast();\n  }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nList<List<int>> subsetSumII(List<int> nums, int target) {\n  List<int> state = []; // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n  nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n  int start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n  List<List<int>> res = []; // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n  backtrack(state, target, nums, start, res);\n  return 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\n    if target == 0 {\n        res.push(state);\n        return;\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\n    for 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\n        if target - choices[i] < 0 {\n            break;\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\n        if i > start && choices[i] == choices[i - 1] {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state.push(choices[i]);\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(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\n        state.pop();\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nfn subset_sum_ii(nums: &mut [i32], target: i32) -> Vec<Vec<i32>> {\n    let state = Vec::new(); // \u72b6\u6001\uff08\u5b50\u96c6\uff09\n    nums.sort(); // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    let start = 0; // \u904d\u5386\u8d77\u59cb\u70b9\n    let mut res = Vec::new(); // \u7ed3\u679c\u5217\u8868\uff08\u5b50\u96c6\u5217\u8868\uff09\n    backtrack(state, target, nums, start, &mut res);\n    res\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\n    if (target == 0) {\n        for (int i = 0; i < stateSize; i++) {\n            res[resSize][i] = state[i];\n        }\n        resColSizes[resSize++] = stateSize;\n        return;\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\n    for (int i = start; i < choicesSize; i++) {\n        // \u526a\u679d\u4e00\uff1a\u82e5\u5b50\u96c6\u548c\u8d85\u8fc7 target \uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\n        if (target - choices[i] < 0) {\n            continue;\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\n        if (i > start && choices[i] == choices[i - 1]) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0 target, start\n        state[stateSize] = choices[i];\n        stateSize++;\n        // \u8fdb\u884c\u4e0b\u4e00\u8f6e\u9009\u62e9\n        backtrack(target - choices[i], choices, choicesSize, i + 1);\n        // \u56de\u9000\uff1a\u64a4\u9500\u9009\u62e9\uff0c\u6062\u590d\u5230\u4e4b\u524d\u7684\u72b6\u6001\n        stateSize--;\n    }\n}\n\n/* \u6c42\u89e3\u5b50\u96c6\u548c II */\nvoid subsetSumII(int *nums, int numsSize, int target) {\n    // \u5bf9 nums \u8fdb\u884c\u6392\u5e8f\n    qsort(nums, numsSize, sizeof(int), cmp);\n    // \u5f00\u59cb\u56de\u6eaf\n    backtrack(target, nums, numsSize, 0);\n}\n
    subset_sum_ii.zig
    [class]{}-[func]{backtrack}\n\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\u6b21\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\u6b21\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\u5b83\u4e0e\u590d\u6742\u5ea6\u5206\u6790\u606f\u606f\u76f8\u5173\u3002\u56e0\u6b64\uff0c\u5728\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\"\"\"\n    res = 0\n    # \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i in range(1, n + 1):\n        res += i\n    return res\n
    iteration.cpp
    /* for \u5faa\u73af */\nint forLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; ++i) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.java
    /* for \u5faa\u73af */\nint forLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.cs
    /* for \u5faa\u73af */\nint ForLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.go
    /* for \u5faa\u73af */\nfunc forLoop(n int) int {\n    res := 0\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i := 1; i <= n; i++ {\n        res += i\n    }\n    return res\n}\n
    iteration.swift
    /* for \u5faa\u73af */\nfunc forLoop(n: Int) -> Int {\n    var res = 0\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i in 1 ... n {\n        res += i\n    }\n    return res\n}\n
    iteration.js
    /* for \u5faa\u73af */\nfunction forLoop(n) {\n    let res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.ts
    /* for \u5faa\u73af */\nfunction forLoop(n: number): number {\n    let res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.dart
    /* for \u5faa\u73af */\nint forLoop(int n) {\n  int res = 0;\n  // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n  for (int i = 1; i <= n; i++) {\n    res += i;\n  }\n  return res;\n}\n
    iteration.rs
    /* for \u5faa\u73af */\nfn for_loop(n: i32) -> i32 {\n    let mut res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i in 1..=n {\n        res += i;\n    }\n    res\n} \n
    iteration.c
    /* for \u5faa\u73af */\nint forLoop(int n) {\n    int res = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        res += i;\n    }\n    return res;\n}\n
    iteration.zig
    // for \u5faa\u73af\nfn forLoop(n: usize) i32 {\n    var res: i32 = 0;\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for (1..n+1) |i| {\n        res = res + @as(i32, @intCast(i));\n    }\n    return res;\n} \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\"\"\"\n    res = 0\n    i = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    # \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while i <= n:\n        res += i\n        i += 1  # \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    return res\n
    iteration.cpp
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.java
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.cs
    /* while \u5faa\u73af */\nint WhileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.go
    /* while \u5faa\u73af */\nfunc whileLoop(n int) int {\n    res := 0\n    // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    i := 1\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    for i <= n {\n        res += i\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++\n    }\n    return res\n}\n
    iteration.swift
    /* while \u5faa\u73af */\nfunc whileLoop(n: Int) -> Int {\n    var res = 0\n    var i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while i <= n {\n        res += i\n        i += 1 // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res\n}\n
    iteration.js
    /* while \u5faa\u73af */\nfunction whileLoop(n) {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.ts
    /* while \u5faa\u73af */\nfunction whileLoop(n: number): number {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.dart
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n  int res = 0;\n  int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n  // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n  while (i <= n) {\n    res += i;\n    i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n  }\n  return res;\n}\n
    iteration.rs
    /* while \u5faa\u73af */\nfn while_loop(n: i32) -> i32 {\n    let mut res = 0;\n    let mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while i <= n {\n        res += i;\n        i += 1; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    res\n}\n
    iteration.c
    /* while \u5faa\u73af */\nint whileLoop(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += i;\n        i++; // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    }\n    return res;\n}\n
    iteration.zig
    // while \u5faa\u73af\nfn whileLoop(n: i32) i32 {\n    var res: i32 = 0;\n    var i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, ..., n-1, n\n    while (i <= n) {\n        res += @intCast(i);\n        i += 1;\n    }\n    return 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\"\"\"\n    res = 0\n    i = 1  # \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    # \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while i <= n:\n        res += i\n        # \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1\n        i *= 2\n    return res\n
    iteration.cpp
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.java
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.cs
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint WhileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 2, 4, 5...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1; \n        i *= 2;\n    }\n    return res;\n}\n
    iteration.go
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n int) int {\n    res := 0\n    // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    i := 1\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    for i <= n {\n        res += i\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++\n        i *= 2\n    }\n    return res\n}\n
    iteration.swift
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunc whileLoopII(n: Int) -> Int {\n    var res = 0\n    var i = 1 // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while i <= n {\n        res += i\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1\n        i *= 2\n    }\n    return res\n}\n
    iteration.js
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n) {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.ts
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfunction whileLoopII(n: number): number {\n    let res = 0;\n    let i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.dart
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n  int res = 0;\n  int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n  // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n  while (i <= n) {\n    res += i;\n    // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n    i++;\n    i *= 2;\n  }\n  return res;\n}\n
    iteration.rs
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nfn while_loop_ii(n: i32) -> i32 {\n    let mut res = 0;\n    let mut i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while i <= n {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1;\n        i *= 2;\n    }\n    res\n}\n
    iteration.c
    /* while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09 */\nint whileLoopII(int n) {\n    int res = 0;\n    int i = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += i;\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i++;\n        i *= 2;\n    }\n    return res;\n}\n
    iteration.zig
    //  while \u5faa\u73af\uff08\u4e24\u6b21\u66f4\u65b0\uff09\nfn whileLoopII(n: i32) i32 {\n    var res: i32 = 0;\n    var i: i32 = 1; // \u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf\n    // \u5faa\u73af\u6c42\u548c 1, 4, 10, ...\n    while (i <= n) {\n        res += @intCast(i);\n        // \u66f4\u65b0\u6761\u4ef6\u53d8\u91cf\n        i += 1;\n        i *= 2;\n    }\n    return 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\"\"\"\n    res = \"\"\n    # \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i in range(1, n + 1):\n        # \u5faa\u73af j = 1, 2, ..., n-1, n\n        for j in range(1, n + 1):\n            res += f\"({i}, {j}), \"\n    return res\n
    iteration.cpp
    /* \u53cc\u5c42 for \u5faa\u73af */\nstring nestedForLoop(int n) {\n    ostringstream res;\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; ++i) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; ++j) {\n            res << \"(\" << i << \", \" << j << \"), \";\n        }\n    }\n    return res.str();\n}\n
    iteration.java
    /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\n    StringBuilder res = new StringBuilder();\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; j++) {\n            res.append(\"(\" + i + \", \" + j + \"), \");\n        }\n    }\n    return res.toString();\n}\n
    iteration.cs
    /* \u53cc\u5c42 for \u5faa\u73af */\nstring NestedForLoop(int n) {\n    StringBuilder res = new();\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; j++) {\n            res.Append($\"({i}, {j}), \");\n        }\n    }\n    return res.ToString();\n}\n
    iteration.go
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n int) string {\n    res := \"\"\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i := 1; i <= n; i++ {\n        for j := 1; j <= n; j++ {\n            // \u5faa\u73af j = 1, 2, ..., n-1, n\n            res += fmt.Sprintf(\"(%d, %d), \", i, j)\n        }\n    }\n    return res\n}\n
    iteration.swift
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunc nestedForLoop(n: Int) -> String {\n    var res = \"\"\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i in 1 ... n {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for j in 1 ... n {\n            res.append(\"(\\(i), \\(j)), \")\n        }\n    }\n    return res\n}\n
    iteration.js
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n) {\n    let res = '';\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (let j = 1; j <= n; j++) {\n            res += `(${i}, ${j}), `;\n        }\n    }\n    return res;\n}\n
    iteration.ts
    /* \u53cc\u5c42 for \u5faa\u73af */\nfunction nestedForLoop(n: number): string {\n    let res = '';\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (let i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (let j = 1; j <= n; j++) {\n            res += `(${i}, ${j}), `;\n        }\n    }\n    return res;\n}\n
    iteration.dart
    /* \u53cc\u5c42 for \u5faa\u73af */\nString nestedForLoop(int n) {\n  String res = \"\";\n  // \u5faa\u73af i = 1, 2, ..., n-1, n\n  for (int i = 1; i <= n; i++) {\n    // \u5faa\u73af j = 1, 2, ..., n-1, n\n    for (int j = 1; j <= n; j++) {\n      res += \"($i, $j), \";\n    }\n  }\n  return res;\n}\n
    iteration.rs
    /* \u53cc\u5c42 for \u5faa\u73af */\nfn nested_for_loop(n: i32) -> String {\n    let mut res = vec![];\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for i in 1..=n {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for j in 1..=n {\n            res.push(format!(\"({}, {}), \", i, j));\n        }\n    }\n    res.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\n    int size = n * n * 26 + 1;\n    char *res = malloc(size * sizeof(char));\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (int i = 1; i <= n; i++) {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (int j = 1; j <= n; j++) {\n            char tmp[26];\n            snprintf(tmp, sizeof(tmp), \"(%d, %d), \", i, j);\n            strncat(res, tmp, size - strlen(res) - 1);\n        }\n    }\n    return res;\n}\n
    iteration.zig
    // \u53cc\u5c42 for \u5faa\u73af\nfn nestedForLoop(allocator: Allocator, n: usize) ![]const u8 {\n    var res = std.ArrayList(u8).init(allocator);\n    defer res.deinit();\n    var buffer: [20]u8 = undefined;\n    // \u5faa\u73af i = 1, 2, ..., n-1, n\n    for (1..n+1) |i| {\n        // \u5faa\u73af j = 1, 2, ..., n-1, n\n        for (1..n+1) |j| {\n            var _str = try std.fmt.bufPrint(&buffer, \"({d}, {d}), \", .{i, j});\n            try res.appendSlice(_str);\n        }\n    }\n    return 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\n    if n == 1:\n        return 1\n    # \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    res = recur(n - 1)\n    # \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res\n
    recursion.cpp
    /* \u9012\u5f52 */\nint recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.java
    /* \u9012\u5f52 */\nint recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.cs
    /* \u9012\u5f52 */\nint Recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = Recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.go
    /* \u9012\u5f52 */\nfunc recur(n int) int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 1 {\n        return 1\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    res := recur(n - 1)\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res\n}\n
    recursion.swift
    /* \u9012\u5f52 */\nfunc recur(n: Int) -> Int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 1 {\n        return 1\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    let res = recur(n: n - 1)\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res\n}\n
    recursion.js
    /* \u9012\u5f52 */\nfunction recur(n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 1) return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    const res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.ts
    /* \u9012\u5f52 */\nfunction recur(n: number): number {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 1) return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    const res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.dart
    /* \u9012\u5f52 */\nint recur(int n) {\n  // \u7ec8\u6b62\u6761\u4ef6\n  if (n == 1) return 1;\n  // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n  int res = recur(n - 1);\n  // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n  return n + res;\n}\n
    recursion.rs
    /* \u9012\u5f52 */\nfn recur(n: i32) -> i32 {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 1 {\n        return 1;\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    let res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    n + res\n}\n
    recursion.c
    /* \u9012\u5f52 */\nint recur(int n) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1)\n        return 1;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    int res = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return n + res;\n}\n
    recursion.zig
    // \u9012\u5f52\u51fd\u6570\nfn recur(n: i32) i32 {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 1) {\n        return 1;\n    }\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    var res: i32 = recur(n - 1);\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    return 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\n    if n == 0:\n        return res\n    # \u5c3e\u9012\u5f52\u8c03\u7528\n    return tail_recur(n - 1, res + n)\n
    recursion.cpp
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.java
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.cs
    /* \u5c3e\u9012\u5f52 */\nint TailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return TailRecur(n - 1, res + n);\n}\n
    recursion.go
    /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n int, res int) int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 0 {\n        return res\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n-1, res+n)\n}\n
    recursion.swift
    /* \u5c3e\u9012\u5f52 */\nfunc tailRecur(n: Int, res: Int) -> Int {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if n == 0 {\n        return res\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n: n - 1, res: res + n)\n}\n
    recursion.js
    /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n, res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 0) return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.ts
    /* \u5c3e\u9012\u5f52 */\nfunction tailRecur(n: number, res: number): number {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n === 0) return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return tailRecur(n - 1, res + n);\n}\n
    recursion.dart
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n  // \u7ec8\u6b62\u6761\u4ef6\n  if (n == 0) return res;\n  // \u5c3e\u9012\u5f52\u8c03\u7528\n  return 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\n    if n == 0 {\n        return res;\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    tail_recur(n - 1, res + n)\n}\n
    recursion.c
    /* \u5c3e\u9012\u5f52 */\nint tailRecur(int n, int res) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (n == 0)\n        return res;\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return 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\n    if (n == 0) {\n        return res;\n    }\n    // \u5c3e\u9012\u5f52\u8c03\u7528\n    return 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\n    if n == 1 or n == 2:\n        return n - 1\n    # \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    res = fib(n - 1) + fib(n - 2)\n    # \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = Fib(n - 1) + Fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if n == 1 || n == 2 {\n        return n - 1\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    res := fib(n-1) + fib(n-2)\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if n == 1 || n == 2 {\n        return n - 1\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    let res = fib(n: n - 1) + fib(n: n - 2)\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n === 1 || n === 2) return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    const res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n === 1 || n === 2) return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    const res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n  if (n == 1 || n == 2) return n - 1;\n  // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n  int res = fib(n - 1) + fib(n - 2);\n  // \u8fd4\u56de\u7ed3\u679c f(n)\n  return 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\n    if n == 1 || n == 2 {\n        return n - 1;\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    let res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c\n    res\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\n    if (n == 1 || n == 2)\n        return n - 1;\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    int res = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\n    if (n == 1 or n == 2) {\n        return n - 1;\n    }\n    // \u9012\u5f52\u8c03\u7528 f(n) = f(n-1) + f(n-2)\n    var res: i32 = fib(n - 1) + fib(n - 2);\n    // \u8fd4\u56de\u7ed3\u679c f(n)\n    return 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\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\u5f02\u66f2\u540c\u5de5\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\u88ab\u4ece\u201c\u8c03\u7528\u6808\u201d\u4e0a\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\n    stack = []\n    res = 0\n    # \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i in range(n, 0, -1):\n        # \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.append(i)\n    # \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while stack:\n        # \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop()\n    # res = 1+2+3+...+n\n    return 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\n    stack<int> stack;\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (!stack.empty()) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.top();\n        stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n    Stack<Integer> stack = new Stack<>();\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (!stack.isEmpty()) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n    Stack<int> stack = new();\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.Push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (stack.Count > 0) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.Pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n    stack := list.New()\n    res := 0\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i := n; i > 0; i-- {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.PushBack(i)\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    for stack.Len() != 0 {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.Back().Value.(int)\n        stack.Remove(stack.Back())\n    }\n    // res = 1+2+3+...+n\n    return 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\n    var stack: [Int] = []\n    var res = 0\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i in stride(from: n, to: 0, by: -1) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.append(i)\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while !stack.isEmpty {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.removeLast()\n    }\n    // res = 1+2+3+...+n\n    return 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\n    const stack = [];\n    let res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (let i = 1; i <= n; i++) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (stack.length) { \n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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 \n    const stack: number[] = [];\n    let res: number = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (let i = 1; i <= n; i++) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (stack.length) { \n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop();\n    }\n    // res = 1+2+3+...+n\n    return 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\n  List<int> stack = [];\n  int res = 0;\n  // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n  for (int i = n; i > 0; i--) {\n    // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n    stack.add(i);\n  }\n  // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n  while (!stack.isEmpty) {\n    // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n    res += stack.removeLast();\n  }\n  // res = 1+2+3+...+n\n  return 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\n    let mut stack = Vec::new();\n    let mut res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for i in (1..=n).rev() {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack.push(i);\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while !stack.is_empty() {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack.pop().unwrap();\n    }\n    // res = 1+2+3+...+n\n    res\n}\n
    recursion.c
    /* \u4f7f\u7528\u8fed\u4ee3\u6a21\u62df\u9012\u5f52 */\nint forLoopRecur(int n) {\n    int stack[1000]; // \u501f\u52a9\u4e00\u4e2a\u5927\u6570\u7ec4\u6765\u6a21\u62df\u6808\n    int top = -1;    // \u6808\u9876\u7d22\u5f15\n    int res = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    for (int i = n; i > 0; i--) {\n        // \u901a\u8fc7\u201c\u5165\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u9012\u201d\n        stack[1 + top++] = i;\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    while (top >= 0) {\n        // \u901a\u8fc7\u201c\u51fa\u6808\u64cd\u4f5c\u201d\u6a21\u62df\u201c\u5f52\u201d\n        res += stack[top--];\n    }\n    // res = 1+2+3+...+n\n    return 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\n    var stack: [n]i32 = undefined;\n    var res: i32 = 0;\n    // \u9012\uff1a\u9012\u5f52\u8c03\u7528\n    var i: usize = n;\n    while (i > 0) {\n        stack[i - 1] = @intCast(i);\n        i -= 1;\n    }\n    // \u5f52\uff1a\u8fd4\u56de\u7ed3\u679c\n    var index: usize = n;\n    while (index > 0) {\n        index -= 1;\n        res += stack[index];\n    }\n    // res = 1+2+3+...+n\n    return res;\n}\n

    \u89c2\u5bdf\u4ee5\u4e0a\u4ee3\u7801\uff0c\u5f53\u9012\u5f52\u8f6c\u5316\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\u5316\uff0c\u4f46\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\u81f3\u5173\u91cd\u8981\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\"\"\"\n    def __init__(self, x: int):\n        self.val: int = x              # \u8282\u70b9\u503c\n        self.next: Node | None = None  # \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n\ndef function() -> int:\n    \"\"\"\u51fd\u6570\"\"\"\n    # \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n\ndef algorithm(n) -> int:  # \u8f93\u5165\u6570\u636e\n    A = 0                 # \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff0c\u4e00\u822c\u7528\u5927\u5199\u5b57\u6bcd\u8868\u793a\uff09\n    b = 0                 # \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    node = Node(0)        # \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    c = function()        # \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return A + b + c      # \u8f93\u51fa\u6570\u636e\n
    /* \u7ed3\u6784\u4f53 */\nstruct Node {\n    int val;\n    Node *next;\n    Node(int x) : val(x), next(nullptr) {}\n};\n\n/* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\n    const int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    Node* node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    int c = func();           // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    int val;\n    Node next;\n    Node(int x) { val = x; }\n}\n\n/* \u51fd\u6570 */\nint function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint algorithm(int n) {        // \u8f93\u5165\u6570\u636e\n    final int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    Node node = new Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    int c = function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node(int x) {\n    int val = x;\n    Node next;\n}\n\n/* \u51fd\u6570 */\nint Function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint Algorithm(int n) {        // \u8f93\u5165\u6570\u636e\n    const int a = 0;          // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    Node node = new(0);       // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    int c = Function();       // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7ed3\u6784\u4f53 */\ntype node struct {\n    val  int\n    next *node\n}\n\n/* \u521b\u5efa node \u7ed3\u6784\u4f53  */\nfunc newNode(val int) *node {\n    return &node{val: val}\n}\n\n/* \u51fd\u6570 */\nfunc function() int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n}\n\nfunc algorithm(n int) int { // \u8f93\u5165\u6570\u636e\n    const a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    b := 0                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    newNode(0)              // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    c := function()         // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c        // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    var val: Int\n    var next: Node?\n\n    init(x: Int) {\n        val = x\n    }\n}\n\n/* \u51fd\u6570 */\nfunc function() -> Int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n}\n\nfunc algorithm(n: Int) -> Int { // \u8f93\u5165\u6570\u636e\n    let a = 0             // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    var b = 0             // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    let node = Node(x: 0) // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    let c = function()    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c      // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    val;\n    next;\n    constructor(val) {\n        this.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\n        this.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n\n/* \u51fd\u6570 */\nfunction constFunc() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\nfunction algorithm(n) {       // \u8f93\u5165\u6570\u636e\n    const a = 0;              // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    let b = 0;                // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    const node = new Node(0); // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    const c = constFunc();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;         // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n    val: number;\n    next: Node | null;\n    constructor(val?: number) {\n        this.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\n        this.next = null;                       // \u6307\u5411\u4e0b\u4e00\u8282\u70b9\u7684\u5f15\u7528\n    }\n}\n\n/* \u51fd\u6570 */\nfunction constFunc(): number {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\nfunction algorithm(n: number): number { // \u8f93\u5165\u6570\u636e\n    const a = 0;                        // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    let b = 0;                          // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    const node = new Node(0);           // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    const c = constFunc();              // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;                   // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u7c7b */\nclass Node {\n  int val;\n  Node next;\n  Node(this.val, [this.next]);\n}\n\n/* \u51fd\u6570 */\nint function() {\n  // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n  return 0;\n}\n\nint algorithm(int n) {  // \u8f93\u5165\u6570\u636e\n  const int a = 0;      // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n  int b = 0;            // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n  Node node = Node(0);  // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n  int c = function();   // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n  return a + b + c;     // \u8f93\u51fa\u6570\u636e\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* \u7ed3\u6784\u4f53 */\nstruct Node {\n    val: i32,\n    next: Option<Rc<RefCell<Node>>>,\n}\n\n/* \u521b\u5efa Node \u7ed3\u6784\u4f53 */\nimpl Node {\n    fn new(val: i32) -> Self {\n        Self { val: val, next: None }\n    }\n}\n\n/* \u51fd\u6570 */\nfn function() -> i32 {      \n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nfn algorithm(n: i32) -> i32 {       // \u8f93\u5165\u6570\u636e\n    const a: i32 = 0;               // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    let mut b = 0;                  // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    let node = Node::new(0);        // \u6682\u5b58\u6570\u636e\uff08\u5bf9\u8c61\uff09\n    let c = function();             // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return a + b + c;               // \u8f93\u51fa\u6570\u636e\n}\n
    /* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0;\n}\n\nint algorithm(int n) { // \u8f93\u5165\u6570\u636e\n    const int a = 0;   // \u6682\u5b58\u6570\u636e\uff08\u5e38\u91cf\uff09\n    int b = 0;         // \u6682\u5b58\u6570\u636e\uff08\u53d8\u91cf\uff09\n    int c = func();    // \u6808\u5e27\u7a7a\u95f4\uff08\u8c03\u7528\u51fd\u6570\uff09\n    return 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):\n    a = 0               # O(1)\n    b = [0] * 10000     # O(1)\n    if n > 10:\n        nums = [0] * n  # O(n)\n
    void algorithm(int n) {\n    int a = 0;               // O(1)\n    vector<int> b(10000);    // O(1)\n    if (n > 10)\n        vector<int> nums(n); // O(n)\n}\n
    void algorithm(int n) {\n    int a = 0;                   // O(1)\n    int[] b = new int[10000];    // O(1)\n    if (n > 10)\n        int[] nums = new int[n]; // O(n)\n}\n
    void Algorithm(int n) {\n    int a = 0;                   // O(1)\n    int[] b = new int[10000];    // O(1)\n    if (n > 10) {\n        int[] nums = new int[n]; // O(n)\n    }\n}\n
    func algorithm(n int) {\n    a := 0                      // O(1)\n    b := make([]int, 10000)     // O(1)\n    var nums []int\n    if n > 10 {\n        nums := make([]int, n)  // O(n)\n    }\n    fmt.Println(a, b, nums)\n}\n
    func algorithm(n: Int) {\n    let a = 0 // O(1)\n    let b = Array(repeating: 0, count: 10000) // O(1)\n    if n > 10 {\n        let nums = Array(repeating: 0, count: n) // O(n)\n    }\n}\n
    function algorithm(n) {\n    const a = 0;                   // O(1)\n    const b = new Array(10000);    // O(1)\n    if (n > 10) {\n        const nums = new Array(n); // O(n)\n    }\n}\n
    function algorithm(n: number): void {\n    const a = 0;                   // O(1)\n    const b = new Array(10000);    // O(1)\n    if (n > 10) {\n        const nums = new Array(n); // O(n)\n    }\n}\n
    void algorithm(int n) {\n  int a = 0;                            // O(1)\n  List<int> b = List.filled(10000, 0);  // O(1)\n  if (n > 10) {\n    List<int> nums = List.filled(n, 0); // O(n)\n  }\n}\n
    fn algorithm(n: i32) {\n    let a = 0;                              // O(1)\n    let b = [0; 10000];                     // O(1)\n    if n > 10 {\n        let nums = vec![0; n as usize];     // O(n)\n    }\n}\n
    void algorithm(int n) {\n    int a = 0;               // O(1)\n    int b[10000];            // O(1)\n    if (n > 10)\n        int 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\n    return 0\n\ndef loop(n: int):\n    \"\"\"\u5faa\u73af\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(1)\"\"\"\n    for _ in range(n):\n        function()\n\ndef recur(n: int) -> int:\n    \"\"\"\u9012\u5f52\u7684\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\"\"\"\n    if n == 1: return\n    return recur(n - 1)\n
    int func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n    if (n == 1) return;\n    return recur(n - 1);\n}\n
    int function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n    for (int i = 0; i < n; i++) {\n        function();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n    if (n == 1) return;\n    return recur(n - 1);\n}\n
    int Function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid Loop(int n) {\n    for (int i = 0; i < n; i++) {\n        Function();\n    }\n}\n/* \u9012\u5f52 O(n) */\nint Recur(int n) {\n    if (n == 1) return 1;\n    return Recur(n - 1);\n}\n
    func function() int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0\n}\n\n/* \u5faa\u73af O(1) */\nfunc loop(n int) {\n    for i := 0; i < n; i++ {\n        function()\n    }\n}\n\n/* \u9012\u5f52 O(n) */\nfunc recur(n int) {\n    if n == 1 {\n        return\n    }\n    recur(n - 1)\n}\n
    @discardableResult\nfunc function() -> Int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0\n}\n\n/* \u5faa\u73af O(1) */\nfunc loop(n: Int) {\n    for _ in 0 ..< n {\n        function()\n    }\n}\n\n/* \u9012\u5f52 O(n) */\nfunc recur(n: Int) {\n    if n == 1 {\n        return\n    }\n    recur(n: n - 1)\n}\n
    function constFunc() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n) {\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n) {\n    if (n === 1) return;\n    return recur(n - 1);\n}\n
    function constFunc(): number {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nfunction loop(n: number): void {\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n/* \u9012\u5f52 O(n) */\nfunction recur(n: number): void {\n    if (n === 1) return;\n    return recur(n - 1);\n}\n
    int function() {\n  // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n  return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n  for (int i = 0; i < n; i++) {\n    function();\n  }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n  if (n == 1) return;\n  return recur(n - 1);\n}\n
    fn function() -> i32 {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nfn loop(n: i32) {\n    for i in 0..n {\n        function();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(n: i32) {\n    if n == 1 {\n        return;\n    }\n    recur(n - 1);\n}\n
    int func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n/* \u5faa\u73af O(1) */\nvoid loop(int n) {\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n/* \u9012\u5f52 O(n) */\nvoid recur(int n) {\n    if (n == 1) return;\n    return 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\n    return 0\n\ndef constant(n: int):\n    \"\"\"\u5e38\u6570\u9636\"\"\"\n    # \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    a = 0\n    nums = [0] * 10000\n    node = ListNode(0)\n    # \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in range(n):\n        c = 0\n    # \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in range(n):\n        function()\n
    space_complexity.cpp
    /* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const int a = 0;\n    int b = 0;\n    vector<int> nums(10000);\n    ListNode node(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n
    space_complexity.java
    /* \u51fd\u6570 */\nint function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    final int a = 0;\n    int b = 0;\n    int[] nums = new int[10000];\n    ListNode node = new ListNode(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        function();\n    }\n}\n
    space_complexity.cs
    /* \u51fd\u6570 */\nint Function() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid Constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    int a = 0;\n    int b = 0;\n    int[] nums = new int[10000];\n    ListNode node = new(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        Function();\n    }\n}\n
    space_complexity.go
    /* \u51fd\u6570 */\nfunc function() int {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c...\n    return 0\n}\n\n/* \u5e38\u6570\u9636 */\nfunc spaceConstant(n int) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const a = 0\n    b := 0\n    nums := make([]int, 10000)\n    ListNode := newNode(0)\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    var c int\n    for i := 0; i < n; i++ {\n        c = 0\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for i := 0; i < n; i++ {\n        function()\n    }\n    fmt.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\n    return 0\n}\n\n/* \u5e38\u6570\u9636 */\nfunc constant(n: Int) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    let a = 0\n    var b = 0\n    let nums = Array(repeating: 0, count: 10000)\n    let node = ListNode(x: 0)\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in 0 ..< n {\n        let c = 0\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for _ in 0 ..< n {\n        function()\n    }\n}\n
    space_complexity.js
    /* \u51fd\u6570 */\nfunction constFunc() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nfunction constant(n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const a = 0;\n    const b = 0;\n    const nums = new Array(10000);\n    const node = new ListNode(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        const c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n
    space_complexity.ts
    /* \u51fd\u6570 */\nfunction constFunc(): number {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\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\n    const a = 0;\n    const b = 0;\n    const nums = new Array(10000);\n    const node = new ListNode(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        const c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (let i = 0; i < n; i++) {\n        constFunc();\n    }\n}\n
    space_complexity.dart
    /* \u51fd\u6570 */\nint function() {\n  // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n  return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n  // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n  final int a = 0;\n  int b = 0;\n  List<int> nums = List.filled(10000, 0);\n  ListNode node = ListNode(0);\n  // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n  for (var i = 0; i < n; i++) {\n    int c = 0;\n  }\n  // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n  for (var i = 0; i < n; i++) {\n    function();\n  }\n}\n
    space_complexity.rs
    /* \u51fd\u6570 */\nfn function() ->i32 {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\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\n    const A: i32 = 0;\n    let b = 0;\n    let nums = vec![0; 10000];\n    let node = ListNode::new(0);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for i in 0..n {\n        let c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for i in 0..n {\n        function();\n    }\n}\n
    space_complexity.c
    /* \u51fd\u6570 */\nint func() {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\n\n/* \u5e38\u6570\u9636 */\nvoid constant(int n) {\n    // \u5e38\u91cf\u3001\u53d8\u91cf\u3001\u5bf9\u8c61\u5360\u7528 O(1) \u7a7a\u95f4\n    const int a = 0;\n    int b = 0;\n    int nums[1000];\n    ListNode *node = newListNode(0);\n    free(node);\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        int c = 0;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    for (int i = 0; i < n; i++) {\n        func();\n    }\n}\n
    space_complexity.zig
    // \u51fd\u6570\nfn function() i32 {\n    // \u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\n    return 0;\n}\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\n    const a: i32 = 0;\n    var b: i32 = 0;\n    var nums = [_]i32{0}**10000;\n    var node = inc.ListNode(i32){.val = 0};\n    var i: i32 = 0;\n    // \u5faa\u73af\u4e2d\u7684\u53d8\u91cf\u5360\u7528 O(1) \u7a7a\u95f4\n    while (i < n) : (i += 1) {\n        var c: i32 = 0;\n        _ = c;\n    }\n    // \u5faa\u73af\u4e2d\u7684\u51fd\u6570\u5360\u7528 O(1) \u7a7a\u95f4\n    i = 0;\n    while (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\n    nums = [0] * n\n    # \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    hmap = dict[int, str]()\n    for i in range(n):\n        hmap[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\n    vector<int> nums(n);\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    vector<ListNode> nodes;\n    for (int i = 0; i < n; i++) {\n        nodes.push_back(ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    unordered_map<int, string> map;\n    for (int i = 0; i < n; i++) {\n        map[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\n    int[] nums = new int[n];\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    List<ListNode> nodes = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n        nodes.add(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    Map<Integer, String> map = new HashMap<>();\n    for (int i = 0; i < n; i++) {\n        map.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\n    int[] nums = new int[n];\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    List<ListNode> nodes = [];\n    for (int i = 0; i < n; i++) {\n        nodes.Add(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    Dictionary<int, string> map = [];\n    for (int i = 0; i < n; i++) {\n        map.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\n    var nodes []*node\n    for i := 0; i < n; i++ {\n        nodes = append(nodes, newNode(i))\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    m := make(map[int]string, n)\n    for i := 0; i < n; i++ {\n        m[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\n    let nums = Array(repeating: 0, count: n)\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let nodes = (0 ..< n).map { ListNode(x: $0) }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let 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\n    const nums = new Array(n);\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const nodes = [];\n    for (let i = 0; i < n; i++) {\n        nodes.push(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const map = new Map();\n    for (let i = 0; i < n; i++) {\n        map.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\n    const nums = new Array(n);\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const nodes: ListNode[] = [];\n    for (let i = 0; i < n; i++) {\n        nodes.push(new ListNode(i));\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    const map = new Map();\n    for (let i = 0; i < n; i++) {\n        map.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\n  List<int> nums = List.filled(n, 0);\n  // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n  List<ListNode> nodes = [];\n  for (var i = 0; i < n; i++) {\n    nodes.add(ListNode(i));\n  }\n  // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n  Map<int, String> map = HashMap();\n  for (var i = 0; i < n; i++) {\n    map.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\n    let mut nums = vec![0; n as usize];\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let mut nodes = Vec::new();\n    for i in 0..n {\n        nodes.push(ListNode::new(i))\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    let mut map = HashMap::new();\n    for i in 0..n {\n        map.insert(i, i.to_string());\n    }\n}\n
    space_complexity.c
    /* \u54c8\u5e0c\u8868 */\ntypedef struct {\n    int key;\n    int val;\n    UT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n\n/* \u7ebf\u6027\u9636 */\nvoid linear(int n) {\n    // \u957f\u5ea6\u4e3a n \u7684\u6570\u7ec4\u5360\u7528 O(n) \u7a7a\u95f4\n    int *nums = malloc(sizeof(int) * n);\n    free(nums);\n\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    ListNode **nodes = malloc(sizeof(ListNode *) * n);\n    for (int i = 0; i < n; i++) {\n        nodes[i] = newListNode(i);\n    }\n    // \u5185\u5b58\u91ca\u653e\n    for (int i = 0; i < n; i++) {\n        free(nodes[i]);\n    }\n    free(nodes);\n\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    HashTable *h = NULL;\n    for (int i = 0; i < n; i++) {\n        HashTable *tmp = malloc(sizeof(HashTable));\n        tmp->key = i;\n        tmp->val = i;\n        HASH_ADD_INT(h, key, tmp);\n    }\n\n    // \u5185\u5b58\u91ca\u653e\n    HashTable *curr, *tmp;\n    HASH_ITER(hh, h, curr, tmp) {\n        HASH_DEL(h, curr);\n        free(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\n    var nums = [_]i32{0}**n;\n    // \u957f\u5ea6\u4e3a n \u7684\u5217\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    var nodes = std.ArrayList(i32).init(std.heap.page_allocator);\n    defer nodes.deinit();\n    var i: i32 = 0;\n    while (i < n) : (i += 1) {\n        try nodes.append(i);\n    }\n    // \u957f\u5ea6\u4e3a n \u7684\u54c8\u5e0c\u8868\u5360\u7528 O(n) \u7a7a\u95f4\n    var map = std.AutoArrayHashMap(i32, []const u8).init(std.heap.page_allocator);\n    defer map.deinit();\n    var j: i32 = 0;\n    while (j < n) : (j += 1) {\n        const string = try std.fmt.allocPrint(std.heap.page_allocator, \"{d}\", .{j});\n        defer std.heap.page_allocator.free(string);\n        try 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\"\"\"\n    print(\"\u9012\u5f52 n =\", n)\n    if n == 1:\n        return\n    linear_recur(n - 1)\n
    space_complexity.cpp
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n    cout << \"\u9012\u5f52 n = \" << n << endl;\n    if (n == 1)\n        return;\n    linearRecur(n - 1);\n}\n
    space_complexity.java
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n    System.out.println(\"\u9012\u5f52 n = \" + n);\n    if (n == 1)\n        return;\n    linearRecur(n - 1);\n}\n
    space_complexity.cs
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid LinearRecur(int n) {\n    Console.WriteLine(\"\u9012\u5f52 n = \" + n);\n    if (n == 1) return;\n    LinearRecur(n - 1);\n}\n
    space_complexity.go
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceLinearRecur(n int) {\n    fmt.Println(\"\u9012\u5f52 n =\", n)\n    if n == 1 {\n        return\n    }\n    spaceLinearRecur(n - 1)\n}\n
    space_complexity.swift
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc linearRecur(n: Int) {\n    print(\"\u9012\u5f52 n = \\(n)\")\n    if n == 1 {\n        return\n    }\n    linearRecur(n: n - 1)\n}\n
    space_complexity.js
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n) {\n    console.log(`\u9012\u5f52 n = ${n}`);\n    if (n === 1) return;\n    linearRecur(n - 1);\n}\n
    space_complexity.ts
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction linearRecur(n: number): void {\n    console.log(`\u9012\u5f52 n = ${n}`);\n    if (n === 1) return;\n    linearRecur(n - 1);\n}\n
    space_complexity.dart
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n  print('\u9012\u5f52 n = $n');\n  if (n == 1) return;\n  linearRecur(n - 1);\n}\n
    space_complexity.rs
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn linear_recur(n: i32) {\n    println!(\"\u9012\u5f52 n = {}\", n);\n    if n == 1 {return};\n    linear_recur(n - 1);\n}\n
    space_complexity.c
    /* \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nvoid linearRecur(int n) {\n    printf(\"\u9012\u5f52 n = %d\\r\\n\", n);\n    if (n == 1)\n        return;\n    linearRecur(n - 1);\n}\n
    space_complexity.zig
    // \u7ebf\u6027\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn linearRecur(comptime n: i32) void {\n    std.debug.print(\"\u9012\u5f52 n = {}\\n\", .{n});\n    if (n == 1) return;\n    linearRecur(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\n    num_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\n    vector<vector<int>> numMatrix;\n    for (int i = 0; i < n; i++) {\n        vector<int> tmp;\n        for (int j = 0; j < n; j++) {\n            tmp.push_back(0);\n        }\n        numMatrix.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\n    int[][] numMatrix = new int[n][n];\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    List<List<Integer>> numList = new ArrayList<>();\n    for (int i = 0; i < n; i++) {\n        List<Integer> tmp = new ArrayList<>();\n        for (int j = 0; j < n; j++) {\n            tmp.add(0);\n        }\n        numList.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\n    int[,] numMatrix = new int[n, n];\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    List<List<int>> numList = [];\n    for (int i = 0; i < n; i++) {\n        List<int> tmp = [];\n        for (int j = 0; j < n; j++) {\n            tmp.Add(0);\n        }\n        numList.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\n    numMatrix := make([][]int, n)\n    for i := 0; i < n; i++ {\n        numMatrix[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\n    let 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\n    const numMatrix = Array(n)\n        .fill(null)\n        .map(() => Array(n).fill(null));\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    const numList = [];\n    for (let i = 0; i < n; i++) {\n        const tmp = [];\n        for (let j = 0; j < n; j++) {\n            tmp.push(0);\n        }\n        numList.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\n    const numMatrix = Array(n)\n        .fill(null)\n        .map(() => Array(n).fill(null));\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    const numList = [];\n    for (let i = 0; i < n; i++) {\n        const tmp = [];\n        for (let j = 0; j < n; j++) {\n            tmp.push(0);\n        }\n        numList.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\n  List<List<int>> numMatrix = List.generate(n, (_) => List.filled(n, 0));\n  // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n  List<List<int>> numList = [];\n  for (var i = 0; i < n; i++) {\n    List<int> tmp = [];\n    for (int j = 0; j < n; j++) {\n      tmp.add(0);\n    }\n    numList.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\n    let num_matrix = vec![vec![0; n as usize]; n as usize];\n    // \u4e8c\u7ef4\u5217\u8868\u5360\u7528 O(n^2) \u7a7a\u95f4\n    let mut num_list = Vec::new();\n    for i in 0..n {\n        let mut tmp = Vec::new();\n        for j in 0..n {\n            tmp.push(0);\n        }\n        num_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\n    int **numMatrix = malloc(sizeof(int *) * n);\n    for (int i = 0; i < n; i++) {\n        int *tmp = malloc(sizeof(int) * n);\n        for (int j = 0; j < n; j++) {\n            tmp[j] = 0;\n        }\n        numMatrix[i] = tmp;\n    }\n\n    // \u5185\u5b58\u91ca\u653e\n    for (int i = 0; i < n; i++) {\n        free(numMatrix[i]);\n    }\n    free(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\n    var nodes = std.ArrayList(std.ArrayList(i32)).init(std.heap.page_allocator);\n    defer nodes.deinit();\n    var i: i32 = 0;\n    while (i < n) : (i += 1) {\n        var tmp = std.ArrayList(i32).init(std.heap.page_allocator);\n        defer tmp.deinit();\n        var j: i32 = 0;\n        while (j < n) : (j += 1) {\n            try tmp.append(0);\n        }\n        try 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\"\"\"\n    if n <= 0:\n        return 0\n    # \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    nums = [0] * n\n    return quadratic_recur(n - 1)\n
    space_complexity.cpp
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n    if (n <= 0)\n        return 0;\n    vector<int> nums(n);\n    cout << \"\u9012\u5f52 n = \" << n << \" \u4e2d\u7684 nums \u957f\u5ea6 = \" << nums.size() << endl;\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.java
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n    if (n <= 0)\n        return 0;\n    // \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    int[] nums = new int[n];\n    System.out.println(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.length);\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.cs
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint QuadraticRecur(int n) {\n    if (n <= 0) return 0;\n    int[] nums = new int[n];\n    Console.WriteLine(\"\u9012\u5f52 n = \" + n + \" \u4e2d\u7684 nums \u957f\u5ea6 = \" + nums.Length);\n    return QuadraticRecur(n - 1);\n}\n
    space_complexity.go
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc spaceQuadraticRecur(n int) int {\n    if n <= 0 {\n        return 0\n    }\n    nums := make([]int, n)\n    fmt.Printf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d \\n\", n, len(nums))\n    return spaceQuadraticRecur(n - 1)\n}\n
    space_complexity.swift
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\n@discardableResult\nfunc quadraticRecur(n: Int) -> Int {\n    if n <= 0 {\n        return 0\n    }\n    // \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    let nums = Array(repeating: 0, count: n)\n    print(\"\u9012\u5f52 n = \\(n) \u4e2d\u7684 nums \u957f\u5ea6 = \\(nums.count)\")\n    return quadraticRecur(n: n - 1)\n}\n
    space_complexity.js
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n) {\n    if (n <= 0) return 0;\n    const nums = new Array(n);\n    console.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.ts
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction quadraticRecur(n: number): number {\n    if (n <= 0) return 0;\n    const nums = new Array(n);\n    console.log(`\u9012\u5f52 n = ${n} \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}`);\n    return quadraticRecur(n - 1);\n}\n
    space_complexity.dart
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n  if (n <= 0) return 0;\n  List<int> nums = List.filled(n, 0);\n  print('\u9012\u5f52 n = $n \u4e2d\u7684 nums \u957f\u5ea6 = ${nums.length}');\n  return quadraticRecur(n - 1);\n}\n
    space_complexity.rs
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn quadratic_recur(n: i32) -> i32 {\n    if n <= 0 {return 0};\n    // \u6570\u7ec4 nums \u957f\u5ea6\u4e3a n, n-1, ..., 2, 1\n    let nums = vec![0; n as usize];\n    println!(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\", n, nums.len());\n    return quadratic_recur(n - 1);\n}\n
    space_complexity.c
    /* \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint quadraticRecur(int n) {\n    if (n <= 0)\n        return 0;\n    int *nums = malloc(sizeof(int) * n);\n    printf(\"\u9012\u5f52 n = %d \u4e2d\u7684 nums \u957f\u5ea6 = %d\\r\\n\", n, n);\n    int res = quadraticRecur(n - 1);\n    free(nums);\n    return res;\n}\n
    space_complexity.zig
    // \u5e73\u65b9\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn quadraticRecur(comptime n: i32) i32 {\n    if (n <= 0) return 0;\n    var nums = [_]i32{0}**n;\n    std.debug.print(\"\u9012\u5f52 n = {} \u4e2d\u7684 nums \u957f\u5ea6 = {}\\n\", .{n, nums.len});\n    return 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\u5c42\u6570\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\"\"\"\n    if n == 0:\n        return None\n    root = TreeNode(0)\n    root.left = build_tree(n - 1)\n    root.right = build_tree(n - 1)\n    return root\n
    space_complexity.cpp
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\n    if (n == 0)\n        return nullptr;\n    TreeNode *root = new TreeNode(0);\n    root->left = buildTree(n - 1);\n    root->right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.java
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode buildTree(int n) {\n    if (n == 0)\n        return null;\n    TreeNode root = new TreeNode(0);\n    root.left = buildTree(n - 1);\n    root.right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.cs
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? BuildTree(int n) {\n    if (n == 0) return null;\n    TreeNode root = new(0) {\n        left = BuildTree(n - 1),\n        right = BuildTree(n - 1)\n    };\n    return root;\n}\n
    space_complexity.go
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n int) *treeNode {\n    if n == 0 {\n        return nil\n    }\n    root := newTreeNode(0)\n    root.left = buildTree(n - 1)\n    root.right = buildTree(n - 1)\n    return root\n}\n
    space_complexity.swift
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunc buildTree(n: Int) -> TreeNode? {\n    if n == 0 {\n        return nil\n    }\n    let root = TreeNode(x: 0)\n    root.left = buildTree(n: n - 1)\n    root.right = buildTree(n: n - 1)\n    return root\n}\n
    space_complexity.js
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n) {\n    if (n === 0) return null;\n    const root = new TreeNode(0);\n    root.left = buildTree(n - 1);\n    root.right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.ts
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nfunction buildTree(n: number): TreeNode | null {\n    if (n === 0) return null;\n    const root = new TreeNode(0);\n    root.left = buildTree(n - 1);\n    root.right = buildTree(n - 1);\n    return root;\n}\n
    space_complexity.dart
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode? buildTree(int n) {\n  if (n == 0) return null;\n  TreeNode root = TreeNode(0);\n  root.left = buildTree(n - 1);\n  root.right = buildTree(n - 1);\n  return 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>>> {\n    if n == 0 {return None};\n    let root = TreeNode::new(0);\n    root.borrow_mut().left = build_tree(n - 1);\n    root.borrow_mut().right = build_tree(n - 1);\n    return Some(root);\n}\n
    space_complexity.c
    /* \u6307\u6570\u9636\uff08\u5efa\u7acb\u6ee1\u4e8c\u53c9\u6811\uff09 */\nTreeNode *buildTree(int n) {\n    if (n == 0)\n        return NULL;\n    TreeNode *root = newTreeNode(0);\n    root->left = buildTree(n - 1);\n    root->right = buildTree(n - 1);\n    return 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) {\n    if (n == 0) return null;\n    const root = try mem_allocator.create(inc.TreeNode(i32));\n    root.init(0);\n    root.left = try buildTree(mem_allocator, n - 1);\n    root.right = try buildTree(mem_allocator, n - 1);\n    return 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):\n    a = 2      # 1 ns\n    a = a + 1  # 1 ns\n    a = a * 2  # 10 ns\n    # \u5faa\u73af n \u6b21\n    for _ in range(n):  # 1 ns\n        print(0)        # 5 ns\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        cout << 0 << endl;         // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        System.out.println(0);     // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid Algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {  // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        Console.WriteLine(0);      // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n int) {\n    a := 2     // 1 ns\n    a = a + 1  // 1 ns\n    a = a * 2  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for i := 0; i < n; i++ {  // 1 ns\n        fmt.Println(a)        // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunc algorithm(n: Int) {\n    var a = 2 // 1 ns\n    a = a + 1 // 1 ns\n    a = a * 2 // 10 ns\n    // \u5faa\u73af n \u6b21\n    for _ in 0 ..< n { // 1 ns\n        print(0) // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n) {\n    var a = 2; // 1 ns\n    a = a + 1; // 1 ns\n    a = a * 2; // 10 ns\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        console.log(0); // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfunction algorithm(n: number): void {\n    var a: number = 2; // 1 ns\n    a = a + 1; // 1 ns\n    a = a * 2; // 10 ns\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        console.log(0); // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n  int a = 2; // 1 ns\n  a = a + 1; // 1 ns\n  a = a * 2; // 10 ns\n  // \u5faa\u73af n \u6b21\n  for (int i = 0; i < n; i++) { // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n    print(0); // 5 ns\n  }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: i32) {\n    let mut a = 2;      // 1 ns\n    a = a + 1;          // 1 ns\n    a = a * 2;          // 10 ns\n    // \u5faa\u73af n \u6b21\n    for _ in 0..n {     // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        println!(\"{}\", 0);  // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nvoid algorithm(int n) {\n    int a = 2;  // 1 ns\n    a = a + 1;  // 1 ns\n    a = a * 2;  // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {   // 1 ns \uff0c\u6bcf\u8f6e\u90fd\u8981\u6267\u884c i++\n        printf(\"%d\", 0);            // 5 ns\n    }\n}\n
    // \u5728\u67d0\u8fd0\u884c\u5e73\u53f0\u4e0b\nfn algorithm(n: usize) void {\n    var a: i32 = 2; // 1 ns\n    a += 1; // 1 ns\n    a *= 2; // 10 ns\n    // \u5faa\u73af n \u6b21\n    for (0..n) |_| { // 1 ns\n        std.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):\n    print(0)\n# \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\ndef algorithm_B(n: int):\n    for _ in range(n):\n        print(0)\n# \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\ndef algorithm_C(n: int):\n    for _ in range(1000000):\n        print(0)\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\n    cout << 0 << endl;\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\n    for (int i = 0; i < n; i++) {\n        cout << 0 << endl;\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        cout << 0 << endl;\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\n    System.out.println(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\n    for (int i = 0; i < n; i++) {\n        System.out.println(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        System.out.println(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmA(int n) {\n    Console.WriteLine(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid AlgorithmB(int n) {\n    for (int i = 0; i < n; i++) {\n        Console.WriteLine(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid AlgorithmC(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        Console.WriteLine(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_A(n int) {\n    fmt.Println(0)\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithm_B(n int) {\n    for i := 0; i < n; i++ {\n        fmt.Println(0)\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithm_C(n int) {\n    for i := 0; i < 1000000; i++ {\n        fmt.Println(0)\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmA(n: Int) {\n    print(0)\n}\n\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunc algorithmB(n: Int) {\n    for _ in 0 ..< n {\n        print(0)\n    }\n}\n\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunc algorithmC(n: Int) {\n    for _ in 0 ..< 1000000 {\n        print(0)\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n) {\n    console.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n) {\n    for (let i = 0; i < n; i++) {\n        console.log(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n) {\n    for (let i = 0; i < 1000000; i++) {\n        console.log(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_A(n: number): void {\n    console.log(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfunction algorithm_B(n: number): void {\n    for (let i = 0; i < n; i++) {\n        console.log(0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfunction algorithm_C(n: number): void {\n    for (let i = 0; i < 1000000; i++) {\n        console.log(0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmA(int n) {\n  print(0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithmB(int n) {\n  for (int i = 0; i < n; i++) {\n    print(0);\n  }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithmC(int n) {\n  for (int i = 0; i < 1000000; i++) {\n    print(0);\n  }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_A(n: i32) {\n    println!(\"{}\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nfn algorithm_B(n: i32) {\n    for _ in 0..n {\n        println!(\"{}\", 0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nfn algorithm_C(n: i32) {\n    for _ in 0..1000000 {\n        println!(\"{}\", 0);\n    }\n}\n
    // \u7b97\u6cd5 A \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_A(int n) {\n    printf(\"%d\", 0);\n}\n// \u7b97\u6cd5 B \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u7ebf\u6027\u9636\nvoid algorithm_B(int n) {\n    for (int i = 0; i < n; i++) {\n        printf(\"%d\", 0);\n    }\n}\n// \u7b97\u6cd5 C \u7684\u65f6\u95f4\u590d\u6742\u5ea6\uff1a\u5e38\u6570\u9636\nvoid algorithm_C(int n) {\n    for (int i = 0; i < 1000000; i++) {\n        printf(\"%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;\n    std.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 {\n    for (0..n) |_| {\n        std.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;\n    for (0..1000000) |_| { \n        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):\n    a = 1      # +1\n    a = a + 1  # +1\n    a = a * 2  # +1\n    # \u5faa\u73af n \u6b21\n    for i in range(n):  # +1\n        print(0)        # +1\n
    void algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        cout << 0 << endl;    // +1\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        System.out.println(0);    // +1\n    }\n}\n
    void Algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        Console.WriteLine(0);   // +1\n    }\n}\n
    func algorithm(n int) {\n    a := 1      // +1\n    a = a + 1   // +1\n    a = a * 2   // +1\n    // \u5faa\u73af n \u6b21\n    for i := 0; i < n; i++ {   // +1\n        fmt.Println(a)         // +1\n    }\n}\n
    func algorithm(n: Int) {\n    var a = 1 // +1\n    a = a + 1 // +1\n    a = a * 2 // +1\n    // \u5faa\u73af n \u6b21\n    for _ in 0 ..< n { // +1\n        print(0) // +1\n    }\n}\n
    function algorithm(n) {\n    var a = 1; // +1\n    a += 1; // +1\n    a *= 2; // +1\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        console.log(0); // +1\n    }\n}\n
    function algorithm(n: number): void{\n    var a: number = 1; // +1\n    a += 1; // +1\n    a *= 2; // +1\n    // \u5faa\u73af n \u6b21\n    for(let i = 0; i < n; i++){ // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        console.log(0); // +1\n    }\n}\n
    void algorithm(int n) {\n  int a = 1; // +1\n  a = a + 1; // +1\n  a = a * 2; // +1\n  // \u5faa\u73af n \u6b21\n  for (int i = 0; i < n; i++) { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n    print(0); // +1\n  }\n}\n
    fn algorithm(n: i32) {\n    let mut a = 1;   // +1\n    a = a + 1;      // +1\n    a = a * 2;      // +1\n\n    // \u5faa\u73af n \u6b21\n    for _ in 0..n { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        println!(\"{}\", 0); // +1\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +1\n    a = a + 1;  // +1\n    a = a * 2;  // +1\n    // \u5faa\u73af n \u6b21\n    for (int i = 0; i < n; i++) {   // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        printf(\"%d\", 0);            // +1\n    }\n}  \n
    fn algorithm(n: usize) void {\n    var a: i32 = 1; // +1\n    a += 1; // +1\n    a *= 2; // +1\n    // \u5faa\u73af n \u6b21\n    for (0..n) |_| { // +1\uff08\u6bcf\u8f6e\u90fd\u6267\u884c i ++\uff09\n        std.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):\n    a = 1      # +0\uff08\u6280\u5de7 1\uff09\n    a = a + n  # +0\uff08\u6280\u5de7 1\uff09\n    # +n\uff08\u6280\u5de7 2\uff09\n    for i in range(5 * n + 1):\n        print(0)\n    # +n*n\uff08\u6280\u5de7 3\uff09\n    for i in range(2 * n):\n        for j in range(n + 1):\n            print(0)\n
    void algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        cout << 0 << endl;\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            cout << 0 << endl;\n        }\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        System.out.println(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            System.out.println(0);\n        }\n    }\n}\n
    void Algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        Console.WriteLine(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            Console.WriteLine(0);\n        }\n    }\n}\n
    func algorithm(n int) {\n    a := 1     // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for i := 0; i < 5 * n + 1; i++ {\n        fmt.Println(0)\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for i := 0; i < 2 * n; i++ {\n        for j := 0; j < n + 1; j++ {\n            fmt.Println(0)\n        }\n    }\n}\n
    func algorithm(n: Int) {\n    var a = 1 // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for _ in 0 ..< (5 * n + 1) {\n        print(0)\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for _ in 0 ..< (2 * n) {\n        for _ in 0 ..< (n + 1) {\n            print(0)\n        }\n    }\n}\n
    function algorithm(n) {\n    let a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (let i = 0; i < 5 * n + 1; i++) {\n        console.log(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (let i = 0; i < 2 * n; i++) {\n        for (let j = 0; j < n + 1; j++) {\n            console.log(0);\n        }\n    }\n}\n
    function algorithm(n: number): void {\n    let a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (let i = 0; i < 5 * n + 1; i++) {\n        console.log(0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (let i = 0; i < 2 * n; i++) {\n        for (let j = 0; j < n + 1; j++) {\n            console.log(0);\n        }\n    }\n}\n
    void algorithm(int n) {\n  int a = 1; // +0\uff08\u6280\u5de7 1\uff09\n  a = a + n; // +0\uff08\u6280\u5de7 1\uff09\n  // +n\uff08\u6280\u5de7 2\uff09\n  for (int i = 0; i < 5 * n + 1; i++) {\n    print(0);\n  }\n  // +n*n\uff08\u6280\u5de7 3\uff09\n  for (int i = 0; i < 2 * n; i++) {\n    for (int j = 0; j < n + 1; j++) {\n      print(0);\n    }\n  }\n}\n
    fn algorithm(n: i32) {\n    let mut a = 1;     // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;        // +0\uff08\u6280\u5de7 1\uff09\n\n    // +n\uff08\u6280\u5de7 2\uff09\n    for i in 0..(5 * n + 1) {\n        println!(\"{}\", 0);\n    }\n\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for i in 0..(2 * n) {\n        for j in 0..(n + 1) {\n            println!(\"{}\", 0);\n        }\n    }\n}\n
    void algorithm(int n) {\n    int a = 1;  // +0\uff08\u6280\u5de7 1\uff09\n    a = a + n;  // +0\uff08\u6280\u5de7 1\uff09\n    // +n\uff08\u6280\u5de7 2\uff09\n    for (int i = 0; i < 5 * n + 1; i++) {\n        printf(\"%d\", 0);\n    }\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for (int i = 0; i < 2 * n; i++) {\n        for (int j = 0; j < n + 1; j++) {\n            printf(\"%d\", 0);\n        }\n    }\n}\n
    fn algorithm(n: usize) void {\n    var a: i32 = 1;     // +0\uff08\u6280\u5de7 1\uff09\n    a = a + @as(i32, @intCast(n));        // +0\uff08\u6280\u5de7 1\uff09\n\n    // +n\uff08\u6280\u5de7 2\uff09\n    for(0..(5 * n + 1)) |_| {\n        std.debug.print(\"{}\\n\", .{0}); \n    }\n\n    // +n*n\uff08\u6280\u5de7 3\uff09\n    for(0..(2 * n)) |_| {\n        for(0..(n + 1)) |_| {\n            std.debug.print(\"{}\\n\", .{0}); \n        }\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\"\"\"\n    count = 0\n    size = 100000\n    for _ in range(size):\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n    int count = 0;\n    int size = 100000;\n    for (int i = 0; i < size; i++)\n        count++;\n    return count;\n}\n
    time_complexity.java
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n    int count = 0;\n    int size = 100000;\n    for (int i = 0; i < size; i++)\n        count++;\n    return count;\n}\n
    time_complexity.cs
    /* \u5e38\u6570\u9636 */\nint Constant(int n) {\n    int count = 0;\n    int size = 100000;\n    for (int i = 0; i < size; i++)\n        count++;\n    return count;\n}\n
    time_complexity.go
    /* \u5e38\u6570\u9636 */\nfunc constant(n int) int {\n    count := 0\n    size := 100000\n    for i := 0; i < size; i++ {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5e38\u6570\u9636 */\nfunc constant(n: Int) -> Int {\n    var count = 0\n    let size = 100_000\n    for _ in 0 ..< size {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5e38\u6570\u9636 */\nfunction constant(n) {\n    let count = 0;\n    const size = 100000;\n    for (let i = 0; i < size; i++) count++;\n    return count;\n}\n
    time_complexity.ts
    /* \u5e38\u6570\u9636 */\nfunction constant(n: number): number {\n    let count = 0;\n    const size = 100000;\n    for (let i = 0; i < size; i++) count++;\n    return count;\n}\n
    time_complexity.dart
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n  int count = 0;\n  int size = 100000;\n  for (var i = 0; i < size; i++) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5e38\u6570\u9636 */\nfn constant(n: i32) -> i32 {\n    _ = n;\n    let mut count = 0;\n    let size = 100_000;\n    for _ in 0..size {\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u5e38\u6570\u9636 */\nint constant(int n) {\n    int count = 0;\n    int size = 100000;\n    int i = 0;\n    for (int i = 0; i < size; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5e38\u6570\u9636\nfn constant(n: i32) i32 {\n    _ = n;\n    var count: i32 = 0;\n    const size: i32 = 100_000;\n    var i: i32 = 0;\n    while(i<size) : (i += 1) {\n        count += 1;\n    }\n    return 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\"\"\"\n    count = 0\n    for _ in range(n):\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++)\n        count++;\n    return count;\n}\n
    time_complexity.java
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++)\n        count++;\n    return count;\n}\n
    time_complexity.cs
    /* \u7ebf\u6027\u9636 */\nint Linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++)\n        count++;\n    return count;\n}\n
    time_complexity.go
    /* \u7ebf\u6027\u9636 */\nfunc linear(n int) int {\n    count := 0\n    for i := 0; i < n; i++ {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u7ebf\u6027\u9636 */\nfunc linear(n: Int) -> Int {\n    var count = 0\n    for _ in 0 ..< n {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u7ebf\u6027\u9636 */\nfunction linear(n) {\n    let count = 0;\n    for (let i = 0; i < n; i++) count++;\n    return count;\n}\n
    time_complexity.ts
    /* \u7ebf\u6027\u9636 */\nfunction linear(n: number): number {\n    let count = 0;\n    for (let i = 0; i < n; i++) count++;\n    return count;\n}\n
    time_complexity.dart
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n  int count = 0;\n  for (var i = 0; i < n; i++) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u7ebf\u6027\u9636 */\nfn linear(n: i32) -> i32 {\n    let mut count = 0;\n    for _ in 0..n {\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u7ebf\u6027\u9636 */\nint linear(int n) {\n    int count = 0;\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u7ebf\u6027\u9636\nfn linear(n: i32) i32 {\n    var count: i32 = 0;\n    var i: i32 = 0;\n    while (i < n) : (i += 1) {\n        count += 1;\n    }\n    return 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\"\"\"\n    count = 0\n    # \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for num in nums:\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(vector<int> &nums) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (int num : nums) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int[] nums) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (int num : nums) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint ArrayTraversal(int[] nums) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    foreach (int num in nums) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums []int) int {\n    count := 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for range nums {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunc arrayTraversal(nums: [Int]) -> Int {\n    var count = 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for _ in nums {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums) {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (let i = 0; i < nums.length; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfunction arrayTraversal(nums: number[]): number {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (let i = 0; i < nums.length; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(List<int> nums) {\n  int count = 0;\n  // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n  for (var _num in nums) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nfn array_traversal(nums: &[i32]) -> i32 {\n    let mut count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for _ in nums {\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09 */\nint arrayTraversal(int *nums, int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u7ebf\u6027\u9636\uff08\u904d\u5386\u6570\u7ec4\uff09\nfn arrayTraversal(nums: []i32) i32 {\n    var count: i32 = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u6b63\u6bd4\n    for (nums) |_| {\n        count += 1;\n    }\n    return 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\"\"\"\n    count = 0\n    # \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for i in range(n):\n        for j in range(n):\n            count += 1\n    return count\n
    time_complexity.cpp
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u5e73\u65b9\u9636 */\nint Quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u5e73\u65b9\u9636 */\nfunc quadratic(n int) int {\n    count := 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for i := 0; i < n; i++ {\n        for j := 0; j < n; j++ {\n            count++\n        }\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5e73\u65b9\u9636 */\nfunc quadratic(n: Int) -> Int {\n    var count = 0\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for _ in 0 ..< n {\n        for _ in 0 ..< n {\n            count += 1\n        }\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5e73\u65b9\u9636 */\nfunction quadratic(n) {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u5e73\u65b9\u9636 */\nfunction quadratic(n: number): number {\n    let count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n  int count = 0;\n  // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n  for (int i = 0; i < n; i++) {\n    for (int j = 0; j < n; j++) {\n      count++;\n    }\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5e73\u65b9\u9636 */\nfn quadratic(n: i32) -> i32 {\n    let mut count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for _ in 0..n {\n        for _ in 0..n {\n            count += 1;\n        }\n    }\n    count\n}\n
    time_complexity.c
    /* \u5e73\u65b9\u9636 */\nint quadratic(int n) {\n    int count = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < n; j++) {\n            count++;\n        }\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5e73\u65b9\u9636\nfn quadratic(n: i32) i32 {\n    var count: i32 = 0;\n    var i: i32 = 0;\n    // \u5faa\u73af\u6b21\u6570\u4e0e\u6570\u7ec4\u957f\u5ea6\u6210\u5e73\u65b9\u5173\u7cfb\n    while (i < n) : (i += 1) {\n        var j: i32 = 0;\n        while (j < n) : (j += 1) {\n            count += 1;\n        }\n    }\n    return 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\"\"\"\n    count = 0  # \u8ba1\u6570\u5668\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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\n        for j in range(i):\n            if nums[j] > nums[j + 1]:\n                # \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                tmp: int = nums[j]\n                nums[j] = nums[j + 1]\n                nums[j + 1] = tmp\n                count += 3  # \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n    return count\n
    time_complexity.cpp
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(vector<int> &nums) {\n    int count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int[] nums) {\n    int count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint BubbleSort(int[] nums) {\n    int count = 0;  // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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 \n        for (int j = 0; j < i; j++) {\n            if (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                count += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums []int) int {\n    count := 0 // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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\n        for j := 0; j < i; j++ {\n            if nums[j] > nums[j+1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                tmp := nums[j]\n                nums[j] = nums[j+1]\n                nums[j+1] = tmp\n                count += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunc bubbleSort(nums: inout [Int]) -> Int {\n    var count = 0 // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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 \n        for j in 0 ..< i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j]\n                nums[j] = nums[j + 1]\n                nums[j + 1] = tmp\n                count += 3 // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums) {\n    let count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfunction bubbleSort(nums: number[]): number {\n    let count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(List<int> nums) {\n  int count = 0; // \u8ba1\u6570\u5668\n  // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n  for (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\n    for (var j = 0; j < i; j++) {\n      if (nums[j] > nums[j + 1]) {\n        // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n        int tmp = nums[j];\n        nums[j] = nums[j + 1];\n        nums[j + 1] = tmp;\n        count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n      }\n    }\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nfn bubble_sort(nums: &mut [i32]) -> i32 {\n    let mut count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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 \n        for j in 0..i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    count\n}\n
    time_complexity.c
    /* \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09 */\nint bubbleSort(int *nums, int n) {\n    int count = 0; // \u8ba1\u6570\u5668\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3; // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5e73\u65b9\u9636\uff08\u5192\u6ce1\u6392\u5e8f\uff09\nfn bubbleSort(nums: []i32) i32 {\n    var count: i32 = 0;  // \u8ba1\u6570\u5668 \n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    var i: i32 = @as(i32, @intCast(nums.len)) - 1;\n    while (i > 0) : (i -= 1) {\n        var 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 \n        while (j < i) : (j += 1) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                var tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                count += 3;  // \u5143\u7d20\u4ea4\u6362\u5305\u542b 3 \u4e2a\u5355\u5143\u64cd\u4f5c\n            }\n        }\n    }\n    return 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)\\) \uff1a

    PythonC++JavaC#GoSwiftJSTSDartRustCZig time_complexity.py
    def exponential(n: int) -> int:\n    \"\"\"\u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\"\"\"\n    count = 0\n    base = 1\n    # \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for _ in range(n):\n        for _ in range(base):\n            count += 1\n        base *= 2\n    # count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count\n
    time_complexity.cpp
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n    int 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)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.java
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n    int 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)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.cs
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Exponential(int n) {\n    int 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)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < bas; j++) {\n            count++;\n        }\n        bas *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.go
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc exponential(n int) int {\n    count, base := 0, 1\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for i := 0; i < n; i++ {\n        for j := 0; j < base; j++ {\n            count++\n        }\n        base *= 2\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count\n}\n
    time_complexity.swift
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc exponential(n: Int) -> Int {\n    var count = 0\n    var base = 1\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for _ in 0 ..< n {\n        for _ in 0 ..< base {\n            count += 1\n        }\n        base *= 2\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count\n}\n
    time_complexity.js
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n) {\n    let count = 0,\n        base = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.ts
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction exponential(n: number): number {\n    let count = 0,\n        base = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for (let i = 0; i < n; i++) {\n        for (let j = 0; j < base; j++) {\n            count++;\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.dart
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n  int 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)\n  for (var i = 0; i < n; i++) {\n    for (var j = 0; j < base; j++) {\n      count++;\n    }\n    base *= 2;\n  }\n  // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n  return count;\n}\n
    time_complexity.rs
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn exponential(n: i32) -> i32 {\n    let mut count = 0;\n    let mut base = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for _ in 0..n {\n        for _ in 0..base {\n            count += 1\n        }\n        base *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    count\n}\n
    time_complexity.c
    /* \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint exponential(int n) {\n    int count = 0;\n    int bas = 1;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    for (int i = 0; i < n; i++) {\n        for (int j = 0; j < bas; j++) {\n            count++;\n        }\n        bas *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return count;\n}\n
    time_complexity.zig
    // \u6307\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn exponential(n: i32) i32 {\n    var count: i32 = 0;\n    var bas: i32 = 1;\n    var i: i32 = 0;\n    // \u7ec6\u80de\u6bcf\u8f6e\u4e00\u5206\u4e3a\u4e8c\uff0c\u5f62\u6210\u6570\u5217 1, 2, 4, 8, ..., 2^(n-1)\n    while (i < n) : (i += 1) {\n        var j: i32 = 0;\n        while (j < bas) : (j += 1) {\n            count += 1;\n        }\n        bas *= 2;\n    }\n    // count = 1 + 2 + 4 + 8 + .. + 2^(n-1) = 2^n - 1\n    return 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\"\"\"\n    if n == 1:\n        return 1\n    return 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) {\n    if (n == 1)\n        return 1;\n    return 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) {\n    if (n == 1)\n        return 1;\n    return 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) {\n    if (n == 1) return 1;\n    return 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 {\n    if n == 1 {\n        return 1\n    }\n    return 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 {\n    if n == 1 {\n        return 1\n    }\n    return 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) {\n    if (n === 1) return 1;\n    return 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 {\n    if (n === 1) return 1;\n    return 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) {\n  if (n == 1) return 1;\n  return 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 {\n    if n == 1 {\n        return 1;\n    }\n    exp_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) {\n    if (n == 1)\n        return 1;\n    return 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 {\n    if (n == 1) return 1;\n    return 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\"\"\"\n    count = 0\n    while n > 1:\n        n = n / 2\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint Logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n /= 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09*/\nfunc logarithmic(n float64) int {\n    count := 0\n    for n > 1 {\n        n = n / 2\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunc logarithmic(n: Double) -> Int {\n    var count = 0\n    var n = n\n    while n > 1 {\n        n = n / 2\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n) {\n    let count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfunction logarithmic(n: number): number {\n    let count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(num n) {\n  int count = 0;\n  while (n > 1) {\n    n = n / 2;\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nfn logarithmic(mut n: f32) -> i32 {\n    let mut count = 0;\n    while n > 1.0 {\n        n = n / 2.0;\n        count += 1;\n    }\n    count\n}\n
    time_complexity.c
    /* \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09 */\nint logarithmic(float n) {\n    int count = 0;\n    while (n > 1) {\n        n = n / 2;\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u5bf9\u6570\u9636\uff08\u5faa\u73af\u5b9e\u73b0\uff09\nfn logarithmic(n: f32) i32 {\n    var count: i32 = 0;\n    var n_var = n;\n    while (n_var > 1)\n    {\n        n_var = n_var / 2;\n        count +=1;\n    }\n    return 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\"\"\"\n    if n <= 1:\n        return 0\n    return log_recur(n / 2) + 1\n
    time_complexity.cpp
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\n    if (n <= 1)\n        return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.java
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\n    if (n <= 1)\n        return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.cs
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint LogRecur(float n) {\n    if (n <= 1) return 0;\n    return LogRecur(n / 2) + 1;\n}\n
    time_complexity.go
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09*/\nfunc logRecur(n float64) int {\n    if n <= 1 {\n        return 0\n    }\n    return logRecur(n/2) + 1\n}\n
    time_complexity.swift
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc logRecur(n: Double) -> Int {\n    if n <= 1 {\n        return 0\n    }\n    return logRecur(n: n / 2) + 1\n}\n
    time_complexity.js
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n) {\n    if (n <= 1) return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.ts
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction logRecur(n: number): number {\n    if (n <= 1) return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.dart
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(num n) {\n  if (n <= 1) return 0;\n  return logRecur(n / 2) + 1;\n}\n
    time_complexity.rs
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn log_recur(n: f32) -> i32 {\n    if n <= 1.0 {\n        return 0;\n    }\n    log_recur(n / 2.0) + 1\n}\n
    time_complexity.c
    /* \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint logRecur(float n) {\n    if (n <= 1)\n        return 0;\n    return logRecur(n / 2) + 1;\n}\n
    time_complexity.zig
    // \u5bf9\u6570\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn logRecur(n: f32) i32 {\n    if (n <= 1) return 0;\n    return 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\"\"\"\n    if n <= 1:\n        return 1\n    count: int = linear_log_recur(n // 2) + linear_log_recur(n // 2)\n    for _ in range(n):\n        count += 1\n    return count\n
    time_complexity.cpp
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\n    if (n <= 1)\n        return 1;\n    int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\n    if (n <= 1)\n        return 1;\n    int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint LinearLogRecur(float n) {\n    if (n <= 1) return 1;\n    int count = LinearLogRecur(n / 2) + LinearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n float64) int {\n    if n <= 1 {\n        return 1\n    }\n    count := linearLogRecur(n/2) + linearLogRecur(n/2)\n    for i := 0.0; i < n; i++ {\n        count++\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunc linearLogRecur(n: Double) -> Int {\n    if n <= 1 {\n        return 1\n    }\n    var count = linearLogRecur(n: n / 2) + linearLogRecur(n: n / 2)\n    for _ in stride(from: 0, to: n, by: 1) {\n        count += 1\n    }\n    return count\n}\n
    time_complexity.js
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n) {\n    if (n <= 1) return 1;\n    let count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (let i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfunction linearLogRecur(n: number): number {\n    if (n <= 1) return 1;\n    let count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (let i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(num n) {\n  if (n <= 1) return 1;\n  int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n  for (var i = 0; i < n; i++) {\n    count++;\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nfn linear_log_recur(n: f32) -> i32 {\n    if n <= 1.0 {\n        return 1;\n    }\n    let mut count = linear_log_recur(n / 2.0) + linear_log_recur(n / 2.0);\n    for _ in 0 ..n as i32 {\n        count += 1;\n    }\n    return count\n}\n
    time_complexity.c
    /* \u7ebf\u6027\u5bf9\u6570\u9636 */\nint linearLogRecur(float n) {\n    if (n <= 1)\n        return 1;\n    int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    for (int i = 0; i < n; i++) {\n        count++;\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u7ebf\u6027\u5bf9\u6570\u9636\nfn linearLogRecur(n: f32) i32 {\n    if (n <= 1) return 1;\n    var count: i32 = linearLogRecur(n / 2) + linearLogRecur(n / 2);\n    var i: f32 = 0;\n    while (i < n) : (i += 1) {\n        count += 1;\n    }\n    return 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\"\"\"\n    if n == 0:\n        return 1\n    count = 0\n    # \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for _ in range(n):\n        count += factorial_recur(n - 1)\n    return count\n
    time_complexity.cpp
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n    if (n == 0)\n        return 1;\n    int count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (int i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.java
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n    if (n == 0)\n        return 1;\n    int count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (int i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.cs
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint FactorialRecur(int n) {\n    if (n == 0) return 1;\n    int count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (int i = 0; i < n; i++) {\n        count += FactorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.go
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n int) int {\n    if n == 0 {\n        return 1\n    }\n    count := 0\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for i := 0; i < n; i++ {\n        count += factorialRecur(n - 1)\n    }\n    return count\n}\n
    time_complexity.swift
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunc factorialRecur(n: Int) -> Int {\n    if n == 0 {\n        return 1\n    }\n    var count = 0\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for _ in 0 ..< n {\n        count += factorialRecur(n: n - 1)\n    }\n    return count\n}\n
    time_complexity.js
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n) {\n    if (n === 0) return 1;\n    let count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (let i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.ts
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfunction factorialRecur(n: number): number {\n    if (n === 0) return 1;\n    let count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for (let i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.dart
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n  if (n == 0) return 1;\n  int count = 0;\n  // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n  for (var i = 0; i < n; i++) {\n    count += factorialRecur(n - 1);\n  }\n  return count;\n}\n
    time_complexity.rs
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nfn factorial_recur(n: i32) -> i32 {\n    if n == 0 {\n        return 1;\n    }\n    let mut count = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    for _ in 0..n {\n        count += factorial_recur(n - 1);\n    }\n    count\n}\n
    time_complexity.c
    /* \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09 */\nint factorialRecur(int n) {\n    if (n == 0)\n        return 1;\n    int count = 0;\n    for (int i = 0; i < n; i++) {\n        count += factorialRecur(n - 1);\n    }\n    return count;\n}\n
    time_complexity.zig
    // \u9636\u4e58\u9636\uff08\u9012\u5f52\u5b9e\u73b0\uff09\nfn factorialRecur(n: i32) i32 {\n    if (n == 0) return 1;\n    var count: i32 = 0;\n    var i: i32 = 0;\n    // \u4ece 1 \u4e2a\u5206\u88c2\u51fa n \u4e2a\n    while (i < n) : (i += 1) {\n        count += factorialRecur(n - 1);\n    }\n    return 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\n    nums = [i for i in range(1, n + 1)]\n    # \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    random.shuffle(nums)\n    return nums\n\ndef find_one(nums: list[int]) -> int:\n    \"\"\"\u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\"\"\"\n    for 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)\n        if nums[i] == 1:\n            return i\n    return -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) {\n    vector<int> nums(n);\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u4f7f\u7528\u7cfb\u7edf\u65f6\u95f4\u751f\u6210\u968f\u673a\u79cd\u5b50\n    unsigned seed = chrono::system_clock::now().time_since_epoch().count();\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    shuffle(nums.begin(), nums.end(), default_random_engine(seed));\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(vector<int> &nums) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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) {\n    Integer[] nums = new Integer[n];\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    Collections.shuffle(Arrays.asList(nums));\n    // Integer[] -> int[]\n    int[] res = new int[n];\n    for (int i = 0; i < n; i++) {\n        res[i] = nums[i];\n    }\n    return res;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int[] nums) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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) {\n    int[] nums = new int[n];\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (int i = 0; i < nums.Length; i++) {\n        int index = new Random().Next(i, nums.Length);\n        (nums[i], nums[index]) = (nums[index], nums[i]);\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint FindOne(int[] nums) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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 {\n    nums := make([]int, n)\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for i := 0; i < n; i++ {\n        nums[i] = i + 1\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    rand.Shuffle(len(nums), func(i, j int) {\n        nums[i], nums[j] = nums[j], nums[i]\n    })\n    return nums\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums []int) int {\n    for 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)\n        if nums[i] == 1 {\n            return i\n        }\n    }\n    return -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 }\n    var nums = Array(1 ... n)\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    nums.shuffle()\n    return nums\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunc findOne(nums: [Int]) -> Int {\n    for 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)\n        if nums[i] == 1 {\n            return i\n        }\n    }\n    return -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) {\n    const nums = Array(n);\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (let i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (let i = 0; i < n; i++) {\n        const r = Math.floor(Math.random() * (i + 1));\n        const temp = nums[i];\n        nums[i] = nums[r];\n        nums[r] = temp;\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums) {\n    for (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)\n        if (nums[i] === 1) {\n            return i;\n        }\n    }\n    return -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[] {\n    const nums = Array(n);\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (let i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (let i = 0; i < n; i++) {\n        const r = Math.floor(Math.random() * (i + 1));\n        const temp = nums[i];\n        nums[i] = nums[r];\n        nums[r] = temp;\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfunction findOne(nums: number[]): number {\n    for (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)\n        if (nums[i] === 1) {\n            return i;\n        }\n    }\n    return -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) {\n  final nums = List.filled(n, 0);\n  // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n  for (var i = 0; i < n; i++) {\n    nums[i] = i + 1;\n  }\n  // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n  nums.shuffle();\n\n  return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(List<int> nums) {\n  for (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)\n    if (nums[i] == 1) return i;\n  }\n\n  return -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 }\n    let mut nums = (1..=n).collect::<Vec<i32>>();\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    nums.shuffle(&mut thread_rng());\n    nums\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nfn find_one(nums: &[i32]) -> Option<usize> {\n    for 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)\n        if nums[i] == 1 {\n            return Some(i);\n        }\n    }\n    None\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\n    int *nums = (int *)malloc(n * sizeof(int));\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (int i = 0; i < n; i++) {\n        nums[i] = i + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    for (int i = n - 1; i > 0; i--) {\n        int j = rand() % (i + 1);\n        int temp = nums[i];\n        nums[i] = nums[j];\n        nums[j] = temp;\n    }\n    return nums;\n}\n\n/* \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15 */\nint findOne(int *nums, int n) {\n    for (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)\n        if (nums[i] == 1)\n            return i;\n    }\n    return -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 {\n    var nums: [n]i32 = undefined;\n    // \u751f\u6210\u6570\u7ec4 nums = { 1, 2, 3, ..., n }\n    for (&nums, 0..) |*num, i| {\n        num.* = @as(i32, @intCast(i)) + 1;\n    }\n    // \u968f\u673a\u6253\u4e71\u6570\u7ec4\u5143\u7d20\n    const rand = std.crypto.random;\n    rand.shuffle(i32, &nums);\n    return nums;\n}\n\n// \u67e5\u627e\u6570\u7ec4 nums \u4e2d\u6570\u5b57 1 \u6240\u5728\u7d22\u5f15\nfn findOne(nums: []i32) i32 {\n    for (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)\n        if (num == 1) return @intCast(i);\n    }\n    return -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\\) \u5b57\u8282 = \\(8\\) \u6bd4\u7279 \uff0c\u53ef\u4ee5\u8868\u793a \\(2^{8}\\) \u4e2a\u6570\u5b57\u3002
    • \u6574\u6570\u7c7b\u578b int \u5360\u7528 \\(4\\) \u5b57\u8282 = \\(32\\) \u6bd4\u7279 \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 \u5b57\u8282 \\(-2^7\\) (\\(-128\\)) \\(2^7 - 1\\) (\\(127\\)) \\(0\\) short 2 \u5b57\u8282 \\(-2^{15}\\) \\(2^{15} - 1\\) \\(0\\) int 4 \u5b57\u8282 \\(-2^{31}\\) \\(2^{31} - 1\\) \\(0\\) long 8 \u5b57\u8282 \\(-2^{63}\\) \\(2^{63} - 1\\) \\(0\\) \u6d6e\u70b9\u6570 float 4 \u5b57\u8282 \\(1.175 \\times 10^{-38}\\) \\(3.403 \\times 10^{38}\\) \\(0.0\\text{f}\\) double 8 \u5b57\u8282 \\(2.225 \\times 10^{-308}\\) \\(1.798 \\times 10^{308}\\) \\(0.0\\) \u5b57\u7b26 char 2 \u5b57\u8282 \\(0\\) \\(2^{16} - 1\\) \\(0\\) \u5e03\u5c14 bool 1 \u5b57\u8282 \\(\\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\u90fd\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\u7684\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\u4e5f\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 \u8fd8\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\u300cEASCII\u300d\u5b57\u7b26\u96c6\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\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 \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 \u5b57\u8282\uff1b\u5982\u679c\u6709\u8d85\u51fa BMP \u7684\u5b57\u7b26\uff0c\u5219\u6bcf\u4e2a\u5b57\u7b26\u5360\u7528 4 \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\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\u5730\u5740\u7a7a\u95f4\u3001\u5185\u5b58\u7ba1\u7406\u3001\u7f13\u5b58\u673a\u5236\u3001\u865a\u62df\u5185\u5b58\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\u4e5f\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 \u539f\u7801\u3001\u53cd\u7801\u548c\u8865\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-magnitude\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 \u5b57\u8282 \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 \u4f4d\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 \u4f4d \uff0c\u5bf9\u5e94 \\(b_{31}\\) \u3002
    • \u6307\u6570\u4f4d \\(\\mathrm{E}\\) \uff1a\u5360 8 \u4f4d \uff0c\u5bf9\u5e94 \\(b_{30} b_{29} \\ldots b_{23}\\) \u3002
    • \u5206\u6570\u4f4d \\(\\mathrm{N}\\) \uff1a\u5360 23 \u4f4d \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\u4e0a\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 \u5360\u7528\u7684\u7a7a\u95f4\u6bd4 UTF-8 \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\u201c\u54c8\u5e0c\u51b2\u7a81\u201d\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\u4e00\u68f5\u6811\u3002\u56e0\u6b64\uff0c\u54c8\u5e0c\u8868\u53ef\u80fd\u540c\u65f6\u5305\u542b\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff08\u6570\u7ec4\u3001\u94fe\u8868\uff09\u548c\u975e\u7ebf\u6027\u6570\u636e\u7ed3\u6784\uff08\u6811\uff09\u3002

    char \u7c7b\u578b\u7684\u957f\u5ea6\u662f 1 \u5b57\u8282\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 \u5b57\u8282\u3002

    \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6570\u636e\u7ed3\u6784\u4e5f\u79f0\u201c\u9759\u6001\u6570\u636e\u7ed3\u6784\u201d \u662f\u5426\u6709\u6b67\u4e49\uff1f\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\u65e7\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\u7531\u7c7b\u5185\u90e8\u81ea\u52a8\u5b8c\u6210\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\u540e\u7eed\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\n    if i > j:\n        return -1\n    # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    m = (i + j) // 2\n    if nums[m] < target:\n        # \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j)\n    elif nums[m] > target:\n        # \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1)\n    else:\n        # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m\n\ndef binary_search(nums: list[int], target: int) -> int:\n    \"\"\"\u4e8c\u5206\u67e5\u627e\"\"\"\n    n = len(nums)\n    # \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(vector<int> &nums, int target) {\n    int n = nums.size();\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int[] nums, int target) {\n    int n = nums.length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return DFS(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return DFS(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint BinarySearch(int[] nums, int target) {\n    int n = nums.Length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if i > j {\n        return -1\n    }\n    //    \u8ba1\u7b97\u7d22\u5f15\u4e2d\u70b9\n    m := i + ((j - i) >> 1)\n    //\u5224\u65ad\u4e2d\u70b9\u4e0e\u76ee\u6807\u5143\u7d20\u5927\u5c0f\n    if nums[m] < target {\n        // \u5c0f\u4e8e\u5219\u9012\u5f52\u53f3\u534a\u6570\u7ec4\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return 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)\n        return dfs(nums, target, i, m-1)\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums []int, target int) int {\n    n := len(nums)\n    return 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\n    if i > j {\n        return -1\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    let m = (i + j) / 2\n    if nums[m] < target {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return 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)\n        return 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\n        return m\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunc binarySearch(nums: [Int], target: Int) -> Int {\n    let n = nums.count\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    const m = i + ((j - i) >> 1);\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums, target) {\n    const n = nums.length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    const m = i + ((j - i) >> 1);\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfunction binarySearch(nums: number[], target: number): number {\n    const n = nums.length;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return 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\n  if (i > j) {\n    return -1;\n  }\n  // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n  int m = (i + j) ~/ 2;\n  if (nums[m] < target) {\n    // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n    return dfs(nums, target, m + 1, j);\n  } else if (nums[m] > target) {\n    // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n    return dfs(nums, target, i, m - 1);\n  } else {\n    // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n    return m;\n  }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(List<int> nums, int target) {\n  int n = nums.length;\n  // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n  return 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\n    if i > j { return -1; }\n    let m: i32 = (i + j) / 2;\n    if nums[m as usize] < target {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if nums[m as usize] > target {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nfn binary_search(nums: &[i32], target: i32) -> i32 {\n    let n = nums.len() as i32;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    dfs(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\n    if (i > j) {\n        return -1;\n    }\n    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    int m = (i + j) / 2;\n    if (nums[m] < target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(m+1, j)\n        return dfs(nums, target, m + 1, j);\n    } else if (nums[m] > target) {\n        // \u9012\u5f52\u5b50\u95ee\u9898 f(i, m-1)\n        return dfs(nums, target, i, m - 1);\n    } else {\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        return m;\n    }\n}\n\n/* \u4e8c\u5206\u67e5\u627e */\nint binarySearch(int nums[], int target, int numsSize) {\n    int n = numsSize;\n    // \u6c42\u89e3\u95ee\u9898 f(0, n-1)\n    return dfs(nums, target, 0, n - 1);\n}\n
    binary_search_recur.zig
    [class]{}-[func]{dfs}\n\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 \u7684\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\u7ed3\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(\n    preorder: list[int],\n    inorder_map: dict[int, int],\n    i: int,\n    l: int,\n    r: int,\n) -> TreeNode | None:\n    \"\"\"\u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb\"\"\"\n    # \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\n    if r - l < 0:\n        return None\n    # \u521d\u59cb\u5316\u6839\u8282\u70b9\n    root = TreeNode(preorder[i])\n    # \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    m = inorder_map[preorder[i]]\n    # \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorder_map, i + 1, l, m - 1)\n    # \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r)\n    # \u8fd4\u56de\u6839\u8282\u70b9\n    return root\n\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\n    inorder_map = {val: i for i, val in enumerate(inorder)}\n    root = dfs(preorder, inorder_map, 0, 0, len(inorder) - 1)\n    return 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\n    if (r - l < 0)\n        return NULL;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode *root = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap[preorder[i]];\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root->left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    unordered_map<int, int> inorderMap;\n    for (int i = 0; i < inorder.size(); i++) {\n        inorderMap[inorder[i]] = i;\n    }\n    TreeNode *root = dfs(preorder, inorderMap, 0, 0, inorder.size() - 1);\n    return 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\n    if (r - l < 0)\n        return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode root = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap.get(preorder[i]);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    Map<Integer, Integer> inorderMap = new HashMap<>();\n    for (int i = 0; i < inorder.length; i++) {\n        inorderMap.put(inorder[i], i);\n    }\n    TreeNode root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n    return 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\n    if (r - l < 0)\n        return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode root = new(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap[preorder[i]];\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = DFS(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = DFS(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    Dictionary<int, int> inorderMap = [];\n    for (int i = 0; i < inorder.Length; i++) {\n        inorderMap.TryAdd(inorder[i], i);\n    }\n    TreeNode? root = DFS(preorder, inorderMap, 0, 0, inorder.Length - 1);\n    return 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\n    if r-l < 0 {\n        return nil\n    }\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    root := NewTreeNode(preorder[i])\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    m := inorderMap[preorder[i]]\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.Left = dfsBuildTree(preorder, inorderMap, i+1, l, m-1)\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.Right = dfsBuildTree(preorder, inorderMap, i+1+m-l, m+1, r)\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root\n}\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\n    inorderMap := make(map[int]int, len(inorder))\n    for i := 0; i < len(inorder); i++ {\n        inorderMap[inorder[i]] = i\n    }\n\n    root := dfsBuildTree(preorder, inorderMap, 0, 0, len(inorder)-1)\n    return 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\n    if r - l < 0 {\n        return nil\n    }\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    let root = TreeNode(x: preorder[i])\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    let m = inorderMap[preorder[i]]!\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1, l: l, r: m - 1)\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder: preorder, inorderMap: inorderMap, i: i + 1 + m - l, l: m + 1, r: r)\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root\n}\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\n    let inorderMap = inorder.enumerated().reduce(into: [:]) { $0[$1.element] = $1.offset }\n    return 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\n    if (r - l < 0) return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    const root = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    const m = inorderMap.get(preorder[i]);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    let inorderMap = new Map();\n    for (let i = 0; i < inorder.length; i++) {\n        inorderMap.set(inorder[i], i);\n    }\n    const root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n    return root;\n}\n
    build_tree.ts
    /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nfunction dfs(\n    preorder: number[],\n    inorderMap: Map<number, number>,\n    i: number,\n    l: number,\n    r: number\n): TreeNode | null {\n    // \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\n    if (r - l < 0) return null;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    const root: TreeNode = new TreeNode(preorder[i]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    const m = inorderMap.get(preorder[i]);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    let inorderMap = new Map<number, number>();\n    for (let i = 0; i < inorder.length; i++) {\n        inorderMap.set(inorder[i], i);\n    }\n    const root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n    return root;\n}\n
    build_tree.dart
    /* \u6784\u5efa\u4e8c\u53c9\u6811\uff1a\u5206\u6cbb */\nTreeNode? dfs(\n  List<int> preorder,\n  Map<int, int> inorderMap,\n  int i,\n  int l,\n  int r,\n) {\n  // \u5b50\u6811\u533a\u95f4\u4e3a\u7a7a\u65f6\u7ec8\u6b62\n  if (r - l < 0) {\n    return null;\n  }\n  // \u521d\u59cb\u5316\u6839\u8282\u70b9\n  TreeNode? root = TreeNode(preorder[i]);\n  // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n  int m = inorderMap[preorder[i]]!;\n  // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n  root.left = dfs(preorder, inorderMap, i + 1, l, m - 1);\n  // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n  root.right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r);\n  // \u8fd4\u56de\u6839\u8282\u70b9\n  return root;\n}\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\n  Map<int, int> inorderMap = {};\n  for (int i = 0; i < inorder.length; i++) {\n    inorderMap[inorder[i]] = i;\n  }\n  TreeNode? root = dfs(preorder, inorderMap, 0, 0, inorder.length - 1);\n  return 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\n    if r - l < 0 { return None; }\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    let root = TreeNode::new(preorder[i as usize]);\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    let m = inorder_map.get(&preorder[i as usize]).unwrap();\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root.borrow_mut().left = dfs(preorder, inorder_map, i + 1, l, m - 1);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root.borrow_mut().right = dfs(preorder, inorder_map, i + 1 + m - l, m + 1, r);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    Some(root)\n}\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\n    let mut inorder_map: HashMap<i32, i32> = HashMap::new();\n    for i in 0..inorder.len() {\n        inorder_map.insert(inorder[i], i as i32);\n    }\n    let root = dfs(preorder, &inorder_map, 0, 0, inorder.len() as i32 - 1);\n    root\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\n    if (r - l < 0)\n        return NULL;\n    // \u521d\u59cb\u5316\u6839\u8282\u70b9\n    TreeNode *root = (TreeNode *)malloc(sizeof(TreeNode));\n    root->val = preorder[i];\n    root->left = NULL;\n    root->right = NULL;\n    // \u67e5\u8be2 m \uff0c\u4ece\u800c\u5212\u5206\u5de6\u53f3\u5b50\u6811\n    int m = inorderMap[preorder[i]];\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u5de6\u5b50\u6811\n    root->left = dfs(preorder, inorderMap, i + 1, l, m - 1, size);\n    // \u5b50\u95ee\u9898\uff1a\u6784\u5efa\u53f3\u5b50\u6811\n    root->right = dfs(preorder, inorderMap, i + 1 + m - l, m + 1, r, size);\n    // \u8fd4\u56de\u6839\u8282\u70b9\n    return root;\n}\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\n    int *inorderMap = (int *)malloc(sizeof(int) * MAX_SIZE);\n    for (int i = 0; i < inorderSize; i++) {\n        inorderMap[inorder[i]] = i;\n    }\n    TreeNode *root = dfs(preorder, inorderMap, 0, 0, inorderSize - 1, inorderSize);\n    free(inorderMap);\n    return root;\n}\n
    build_tree.zig
    [class]{}-[func]{dfs}\n\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\u4e2a\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\u5f97\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\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 \u7684\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 \u7684\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 \u7684\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\u4e00\u4e2a\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\n    pan = src.pop()\n    # \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.append(pan)\n\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\n    if i == 1:\n        move(src, tar)\n        return\n    # \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf)\n    # \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar)\n\ndef solve_hanota(A: list[int], B: list[int], C: list[int]):\n    \"\"\"\u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898\"\"\"\n    n = len(A)\n    # \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    int pan = src.back();\n    src.pop_back();\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push_back(pan);\n}\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\n    if (i == 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(vector<int> &A, vector<int> &B, vector<int> &C) {\n    int n = A.size();\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    Integer pan = src.remove(src.size() - 1);\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.add(pan);\n}\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\n    if (i == 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<Integer> A, List<Integer> B, List<Integer> C) {\n    int n = A.size();\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    int pan = src[^1];\n    src.RemoveAt(src.Count - 1);\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.Add(pan);\n}\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\n    if (i == 1) {\n        Move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    DFS(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    Move(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\n    DFS(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid SolveHanota(List<int> A, List<int> B, List<int> C) {\n    int n = A.Count;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    DFS(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\n    pan := src.Back()\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.PushBack(pan.Value)\n    // \u79fb\u9664 src \u9876\u90e8\u5706\u76d8\n    src.Remove(pan)\n}\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\n    if i == 1 {\n        move(src, tar)\n        return\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfsHanota(i-1, src, tar, buf)\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfsHanota(i-1, buf, src, tar)\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A, B, C *list.List) {\n    n := A.Len()\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfsHanota(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\n    let pan = src.popLast()!\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.append(pan)\n}\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\n    if i == 1 {\n        move(src: &src, tar: &tar)\n        return\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(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\n    move(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\n    dfs(i: i - 1, src: &buf, buf: &src, tar: &tar)\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunc solveHanota(A: inout [Int], B: inout [Int], C: inout [Int]) {\n    let 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\n    dfs(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\n    const pan = src.pop();\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push(pan);\n}\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\n    if (i === 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A, B, C) {\n    const n = A.length;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    const pan = src.pop();\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push(pan);\n}\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\n    if (i === 1) {\n        move(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move(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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfunction solveHanota(A: number[], B: number[], C: number[]): void {\n    const n = A.length;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n  int pan = src.removeLast();\n  // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n  tar.add(pan);\n}\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\n  if (i == 1) {\n    move(src, tar);\n    return;\n  }\n  // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n  dfs(i - 1, src, tar, buf);\n  // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n  move(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\n  dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nvoid solveHanota(List<int> A, List<int> B, List<int> C) {\n  int n = A.length;\n  // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n  dfs(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\n    let pan = src.remove(src.len() - 1);\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar.push(pan);\n}\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\n    if i == 1 {\n        move_pan(src, tar);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(i - 1, src, tar, buf);\n    // \u5b50\u95ee\u9898 f(1) \uff1a\u5c06 src \u5269\u4f59\u4e00\u4e2a\u5706\u76d8\u79fb\u5230 tar\n    move_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\n    dfs(i - 1, buf, src, tar);\n}\n\n/* \u6c42\u89e3\u6c49\u8bfa\u5854\u95ee\u9898 */\nfn solve_hanota(A: &mut Vec<i32>, B: &mut Vec<i32>, C: &mut Vec<i32>) {\n    let n = A.len() as i32;\n    // \u5c06 A \u9876\u90e8 n \u4e2a\u5706\u76d8\u501f\u52a9 B \u79fb\u5230 C\n    dfs(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\n    int pan = src[*srcSize - 1];\n    src[*srcSize - 1] = 0;\n    (*srcSize)--;\n    // \u5c06\u5706\u76d8\u653e\u5165 tar \u9876\u90e8\n    tar[*tarSize] = pan;\n    (*tarSize)++;\n}\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\n    if (i == 1) {\n        move(src, srcSize, tar, tarSize);\n        return;\n    }\n    // \u5b50\u95ee\u9898 f(i-1) \uff1a\u5c06 src \u9876\u90e8 i-1 \u4e2a\u5706\u76d8\u501f\u52a9 tar \u79fb\u5230 buf\n    dfs(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\n    move(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\n    dfs(i - 1, buf, bufSize, src, srcSize, tar, tarSize);\n}\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\n    dfs(*ASize, A, ASize, B, BSize, C, CSize);\n}\n
    hanota.zig
    [class]{}-[func]{move}\n\n[class]{}-[func]{dfs}\n\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\"\"\"\n    n = len(cost) - 1\n    if n == 1 or n == 2:\n        return cost[n]\n    # \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp = [0] * (n + 1)\n    # \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[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\n    for i in range(3, n + 1):\n        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\n    return 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) {\n    int n = cost.size() - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    vector<int> dp(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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) {\n    int n = cost.length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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) {\n    int n = cost.Length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = Math.Min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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 {\n    n := len(cost) - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    min := func(a, b int) int {\n        if a < b {\n            return a\n        }\n        return b\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp := make([]int, n+1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1]\n    dp[2] = cost[2]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        dp[i] = min(dp[i-1], dp[i-2]) + cost[i]\n    }\n    return 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 {\n    let n = cost.count - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = Array(repeating: 0, count: n + 1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1]\n    dp[2] = cost[2]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in stride(from: 3, through: n, by: 1) {\n        dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i]\n    }\n    return 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) {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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 {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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) {\n  int n = cost.length - 1;\n  if (n == 1 || n == 2) return cost[n];\n  // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n  List<int> dp = List.filled(n + 1, 0);\n  // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n  dp[1] = cost[1];\n  dp[2] = cost[2];\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n  for (int i = 3; i <= n; i++) {\n    dp[i] = min(dp[i - 1], dp[i - 2]) + cost[i];\n  }\n  return 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 {\n    let n = cost.len() - 1;\n    if n == 1 || n == 2 { return cost[n]; }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    let mut dp = vec![-1; n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in 3..=n {\n        dp[i] = cmp::min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    dp[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) {\n    int n = costSize - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int *dp = calloc(n + 1, sizeof(int));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = myMin(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    int res = dp[n];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = cost.len - 1;\n    if (n == 1 or n == 2) {\n        return cost[n];\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = [_]i32{-1} ** (n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = cost[1];\n    dp[2] = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        dp[i] = @min(dp[i - 1], dp[i - 2]) + cost[i];\n    }\n    return 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\"\"\"\n    n = len(cost) - 1\n    if n == 1 or n == 2:\n        return cost[n]\n    a, b = cost[1], cost[2]\n    for i in range(3, n + 1):\n        a, b = b, min(a, b) + cost[i]\n    return 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) {\n    int n = cost.size() - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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) {\n    int n = cost.length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = Math.min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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) {\n    int n = cost.Length - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = Math.Min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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 {\n    n := len(cost) - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    min := func(a, b int) int {\n        if a < b {\n            return a\n        }\n        return b\n    }\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    a, 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\n    for i := 3; i <= n; i++ {\n        tmp := b\n        b = min(a, tmp) + cost[i]\n        a = tmp\n    }\n    return 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 {\n    let n = cost.count - 1\n    if n == 1 || n == 2 {\n        return cost[n]\n    }\n    var (a, b) = (cost[1], cost[2])\n    for i in stride(from: 3, through: n, by: 1) {\n        (a, b) = (b, min(a, b) + cost[i])\n    }\n    return 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) {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    let a = cost[1],\n        b = cost[2];\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = Math.min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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 {\n    const n = cost.length - 1;\n    if (n === 1 || n === 2) {\n        return cost[n];\n    }\n    let a = cost[1],\n        b = cost[2];\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = Math.min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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) {\n  int n = cost.length - 1;\n  if (n == 1 || n == 2) return cost[n];\n  int a = cost[1], b = cost[2];\n  for (int i = 3; i <= n; i++) {\n    int tmp = b;\n    b = min(a, tmp) + cost[i];\n    a = tmp;\n  }\n  return 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 {\n    let n = cost.len() - 1;\n    if n == 1 || n == 2 { return cost[n] };\n    let (mut a, mut b) = (cost[1], cost[2]);\n    for i in 3..=n {\n        let tmp = b;\n        b = cmp::min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    b\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) {\n    int n = costSize - 1;\n    if (n == 1 || n == 2)\n        return cost[n];\n    int a = cost[1], b = cost[2];\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = myMin(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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 {\n    var n = cost.len - 1;\n    if (n == 1 or n == 2) {\n        return cost[n];\n    }\n    var a = cost[1];\n    var b = cost[2];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        var tmp = b;\n        b = @min(a, tmp) + cost[i];\n        a = tmp;\n    }\n    return 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\u4e00\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\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\"\"\"\n    if n == 1 or n == 2:\n        return 1\n    # \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp = [[0] * 3 for _ in range(n + 1)]\n    # \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1], dp[1][2] = 1, 0\n    dp[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\n    for i in range(3, n + 1):\n        dp[i][1] = dp[i - 1][2]\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2]\n    return 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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    vector<vector<int>> dp(n + 1, vector<int>(3, 0));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[][] dp = new int[n + 1][3];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[,] dp = new int[n + 1, 3];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1, 1] = 1;\n    dp[1, 2] = 0;\n    dp[2, 1] = 0;\n    dp[2, 2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i, 1] = dp[i - 1, 2];\n        dp[i, 2] = dp[i - 2, 1] + dp[i - 2, 2];\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return 1\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp := make([][3]int, n+1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1\n    dp[1][2] = 0\n    dp[2][1] = 0\n    dp[2][2] = 1\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        dp[i][1] = dp[i-1][2]\n        dp[i][2] = dp[i-2][1] + dp[i-2][2]\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return 1\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var 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\n    dp[1][1] = 1\n    dp[1][2] = 0\n    dp[2][1] = 0\n    dp[2][2] = 1\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in stride(from: 3, through: n, by: 1) {\n        dp[i][1] = dp[i - 1][2]\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2]\n    }\n    return 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) {\n    if (n === 1 || n === 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const 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\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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 {\n    if (n === 1 || n === 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = Array.from({ length: n + 1 }, () => new Array(3));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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) {\n  if (n == 1 || n == 2) {\n    return 1;\n  }\n  // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n  List<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\n  dp[1][1] = 1;\n  dp[1][2] = 0;\n  dp[2][1] = 0;\n  dp[2][2] = 1;\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n  for (int i = 3; i <= n; i++) {\n    dp[i][1] = dp[i - 1][2];\n    dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n  }\n  return 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 {\n    if n == 1 || n == 2 { return 1 };\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    let mut dp = vec![vec![-1; 3]; n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in 3..=n {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    dp[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) {\n    if (n == 1 || n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(3, sizeof(int));\n    }\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    int res = dp[n][1] + dp[n][2];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    free(dp);\n    return 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 {\n    if (n == 1 or n == 2) {\n        return 1;\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = [_][3]i32{ [_]i32{ -1, -1, -1 } } ** (n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1][1] = 1;\n    dp[1][2] = 0;\n    dp[2][1] = 0;\n    dp[2][2] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        dp[i][1] = dp[i - 1][2];\n        dp[i][2] = dp[i - 2][1] + dp[i - 2][2];\n    }\n    return 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\u201d\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\n    if i == 0 and j == 0:\n        return grid[0][0]\n    # \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 or j < 0:\n        return inf\n    # \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    up = min_path_sum_dfs(grid, i - 1, j)\n    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\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = minPathSumDFS(grid, i - 1, j);\n    int left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = minPathSumDFS(grid, i - 1, j);\n    int left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = MinPathSumDFS(grid, i - 1, j);\n    int left = MinPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if i == 0 && j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return 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\n    up := minPathSumDFS(grid, i-1, j)\n    left := minPathSumDFS(grid, i, j-1)\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if i == 0, j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return .max\n    }\n    // \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    let up = minPathSumDFS(grid: grid, i: i - 1, j: j)\n    let 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\n    return 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\n    if (i === 0 && j === 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFS(grid, i - 1, j);\n    const left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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(\n    grid: Array<Array<number>>,\n    i: number,\n    j: number\n): number {\n    // \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\n    if (i === 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u8ba1\u7b97\u4ece\u5de6\u4e0a\u89d2\u5230 (i-1, j) \u548c (i, j-1) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFS(grid, i - 1, j);\n    const left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n  if (i == 0 && j == 0) {\n    return grid[0][0];\n  }\n  // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n  if (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\n    return 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\n  int up = minPathSumDFS(grid, i - 1, j);\n  int left = minPathSumDFS(grid, i, j - 1);\n  // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n  return 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\n    if i == 0 && j == 0 {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return 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\n    let up = min_path_sum_dfs(grid, i - 1, j);\n    let 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\n    std::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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return 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\n    int up = minPathSumDFS(grid, i - 1, j);\n    int left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return 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\n    if (i == 0 and j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 or j < 0) {\n        return 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\n    var up = minPathSumDFS(grid, i - 1, j);\n    var left = minPathSumDFS(grid, i, j - 1);\n    // \u8fd4\u56de\u4ece\u5de6\u4e0a\u89d2\u5230 (i, j) \u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    return @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(\n    grid: 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\n    if i == 0 and j == 0:\n        return grid[0][0]\n    # \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 or j < 0:\n        return inf\n    # \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][j] != -1:\n        return mem[i][j]\n    # \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    up = min_path_sum_dfs_mem(grid, mem, i - 1, j)\n    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\n    mem[i][j] = min(left, up) + grid[i][j]\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return INT_MAX;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = minPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = min(left, up) != INT_MAX ? min(left, up) + grid[i][j] : INT_MAX;\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Integer.MAX_VALUE;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = minPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = Math.min(left, up) + grid[i][j];\n    return 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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return int.MaxValue;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = MinPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = Math.Min(left, up) + grid[i][j];\n    return 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\n    if i == 0 && j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return math.MaxInt\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][j] != -1 {\n        return mem[i][j]\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    up := minPathSumDFSMem(grid, mem, i-1, j)\n    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\n    mem[i][j] = int(math.Min(float64(left), float64(up))) + grid[i][j]\n    return 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\n    if i == 0, j == 0 {\n        return grid[0][0]\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return .max\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][j] != -1 {\n        return mem[i][j]\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    let up = minPathSumDFSMem(grid: grid, mem: &mem, i: i - 1, j: j)\n    let 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\n    mem[i][j] = min(left, up) + grid[i][j]\n    return 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\n    if (i === 0 && j === 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] !== -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFSMem(grid, mem, i - 1, j);\n    const 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\n    mem[i][j] = Math.min(left, up) + grid[i][j];\n    return mem[i][j];\n}\n
    min_path_sum.ts
    /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction minPathSumDFSMem(\n    grid: Array<Array<number>>,\n    mem: Array<Array<number>>,\n    i: number,\n    j: number\n): number {\n    // \u82e5\u4e3a\u5de6\u4e0a\u89d2\u5355\u5143\u683c\uff0c\u5219\u7ec8\u6b62\u641c\u7d22\n    if (i === 0 && j === 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return Infinity;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    const up = minPathSumDFSMem(grid, mem, i - 1, j);\n    const 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\n    mem[i][j] = Math.min(left, up) + grid[i][j];\n    return 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\n  if (i == 0 && j == 0) {\n    return grid[0][0];\n  }\n  // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n  if (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\n    return BigInt.from(2).pow(31).toInt();\n  }\n  // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n  if (mem[i][j] != -1) {\n    return mem[i][j];\n  }\n  // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n  int up = minPathSumDFSMem(grid, mem, i - 1, j);\n  int 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\n  mem[i][j] = min(left, up) + grid[i][j];\n  return 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\n    if i == 0 && j == 0 {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if i < 0 || j < 0 {\n        return i32::MAX;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i as usize][j as usize] != -1 {\n        return mem[i as usize][j as usize];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    let up = min_path_sum_dfs_mem(grid, mem, i - 1, j);\n    let 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\n    mem[i as usize][j as usize] = std::cmp::min(left, up) + grid[i as usize][j as usize];\n    mem[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\n    if (i == 0 && j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 || j < 0) {\n        return INT_MAX;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][j] != -1) {\n        return mem[i][j];\n    }\n    // \u5de6\u8fb9\u548c\u4e0a\u8fb9\u5355\u5143\u683c\u7684\u6700\u5c0f\u8def\u5f84\u4ee3\u4ef7\n    int up = minPathSumDFSMem(grid, mem, i - 1, j);\n    int 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\n    mem[i][j] = myMin(left, up) != INT_MAX ? myMin(left, up) + grid[i][j] : INT_MAX;\n    return 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\n    if (i == 0 and j == 0) {\n        return grid[0][0];\n    }\n    // \u82e5\u884c\u5217\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de +\u221e \u4ee3\u4ef7\n    if (i < 0 or j < 0) {\n        return std.math.maxInt(i32);\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] != -1) {\n        return 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\n    var up = minPathSumDFSMem(grid, mem, i - 1, j);\n    var 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\n    mem[@as(usize, @intCast(i))][@as(usize, @intCast(j))] = @min(left, up) + grid[@as(usize, @intCast(i))][@as(usize, @intCast(j))];\n    return 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\"\"\"\n    n, m = len(grid), len(grid[0])\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * m for _ in range(n)]\n    dp[0][0] = grid[0][0]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in range(1, m):\n        dp[0][j] = dp[0][j - 1] + grid[0][j]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i in range(1, n):\n        dp[i][0] = dp[i - 1][0] + grid[i][0]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in range(1, n):\n        for j in range(1, m):\n            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\n    return 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) {\n    int n = grid.size(), m = grid[0].size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n, vector<int>(m));\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.length, m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n][m];\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.Length, m = grid[0].Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n, m];\n    dp[0, 0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0, j] = dp[0, j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i, 0] = dp[i - 1, 0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i, j] = Math.Min(dp[i, j - 1], dp[i - 1, j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    n, m := len(grid), len(grid[0])\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n)\n    for i := 0; i < n; i++ {\n        dp[i] = make([]int, m)\n    }\n    dp[0][0] = grid[0][0]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j := 1; j < m; j++ {\n        dp[0][j] = dp[0][j-1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i := 1; i < n; i++ {\n        dp[i][0] = dp[i-1][0] + grid[i][0]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i < n; i++ {\n        for j := 1; j < m; j++ {\n            dp[i][j] = int(math.Min(float64(dp[i][j-1]), float64(dp[i-1][j]))) + grid[i][j]\n        }\n    }\n    return 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 {\n    let n = grid.count\n    let m = grid[0].count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: m), count: n)\n    dp[0][0] = grid[0][0]\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in stride(from: 1, to: m, by: 1) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i in stride(from: 1, to: n, by: 1) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in stride(from: 1, to: n, by: 1) {\n        for j in stride(from: 1, to: m, by: 1) {\n            dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j]\n        }\n    }\n    return dp[n - 1][m - 1]\n}\n
    min_path_sum.js
    /* \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction minPathSumDP(grid) {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n }, () =>\n        Array.from({ length: m }, () => 0)\n    );\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (let i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i < n; i++) {\n        for (let j = 1; j < m; j++) {\n            dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n }, () =>\n        Array.from({ length: m }, () => 0)\n    );\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (let i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i < n; i++) {\n        for (let j: number = 1; j < m; j++) {\n            dp[i][j] = Math.min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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) {\n  int n = grid.length, m = grid[0].length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n, (i) => List.filled(m, 0));\n  dp[0][0] = grid[0][0];\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n  for (int j = 1; j < m; j++) {\n    dp[0][j] = dp[0][j - 1] + grid[0][j];\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n  for (int i = 1; i < n; i++) {\n    dp[i][0] = dp[i - 1][0] + grid[i][0];\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n  for (int i = 1; i < n; i++) {\n    for (int j = 1; j < m; j++) {\n      dp[i][j] = min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n    }\n  }\n  return 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 {\n    let (n, m) = (grid.len(), grid[0].len());\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; m]; n];\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in 1..m {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for i in 1..n {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in 1..n {\n        for j in 1..m {\n            dp[i][j] = std::cmp::min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    dp[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\n    int **dp = malloc(n * sizeof(int *));\n    for (int i = 0; i < n; i++) {\n        dp[i] = calloc(m, sizeof(int));\n    }\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (int i = 1; i < n; i++) {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i < n; i++) {\n        for (int j = 1; j < m; j++) {\n            dp[i][j] = myMin(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    int res = dp[n - 1][m - 1];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i < n; i++) {\n        free(dp[i]);\n    }\n    return res;\n}\n
    min_path_sum.zig
    // \u6700\u5c0f\u8def\u5f84\u548c\uff1a\u52a8\u6001\u89c4\u5212\nfn minPathSumDP(comptime grid: anytype) i32 {\n    comptime var n = grid.len;\n    comptime var m = grid[0].len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][m]i32{[_]i32{0} ** m} ** n;\n    dp[0][0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (1..m) |j| {\n        dp[0][j] = dp[0][j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    for (1..n) |i| {\n        dp[i][0] = dp[i - 1][0] + grid[i][0];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (1..n) |i| {\n        for (1..m) |j| {\n            dp[i][j] = @min(dp[i][j - 1], dp[i - 1][j]) + grid[i][j];\n        }\n    }\n    return 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\"\"\"\n    n, m = len(grid), len(grid[0])\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * m\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0]\n    for j in range(1, m):\n        dp[j] = dp[j - 1] + grid[0][j]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in range(1, n):\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0]\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in range(1, m):\n            dp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\n    return 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) {\n    int n = grid.size(), m = grid[0].size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(m);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.length, m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[m];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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) {\n    int n = grid.Length, m = grid[0].Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[m];\n    dp[0] = grid[0][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = Math.Min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    n, m := len(grid), len(grid[0])\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, m)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0]\n    for j := 1; j < m; j++ {\n        dp[j] = dp[j-1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i < n; i++ {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0]\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j := 1; j < m; j++ {\n            dp[j] = int(math.Min(float64(dp[j-1]), float64(dp[j]))) + grid[i][j]\n        }\n    }\n    return 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 {\n    let n = grid.count\n    let m = grid[0].count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: m)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0]\n    for j in stride(from: 1, to: m, by: 1) {\n        dp[j] = dp[j - 1] + grid[0][j]\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in stride(from: 1, to: n, by: 1) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0]\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in stride(from: 1, to: m, by: 1) {\n            dp[j] = min(dp[j - 1], dp[j]) + grid[i][j]\n        }\n    }\n    return 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) {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = new Array(m);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (let j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j < m; j++) {\n            dp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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 {\n    const n = grid.length,\n        m = grid[0].length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = new Array(m);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (let j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j < m; j++) {\n            dp[j] = Math.min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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) {\n  int n = grid.length, m = grid[0].length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(m, 0);\n  dp[0] = grid[0][0];\n  for (int j = 1; j < m; j++) {\n    dp[j] = dp[j - 1] + grid[0][j];\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n  for (int i = 1; i < n; i++) {\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    dp[0] = dp[0] + grid[i][0];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n    for (int j = 1; j < m; j++) {\n      dp[j] = min(dp[j - 1], dp[j]) + grid[i][j];\n    }\n  }\n  return 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 {\n    let (n, m) = (grid.len(), grid[0].len());\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; m];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for j in 1..m {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in 1..n {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in 1..m {\n            dp[j] = std::cmp::min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    dp[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\n    int *dp = calloc(m, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (int j = 1; j < m; j++) {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i < n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j < m; j++) {\n            dp[j] = myMin(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    int res = dp[m - 1];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = grid.len;\n    comptime var m = grid[0].len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** m;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    dp[0] = grid[0][0];\n    for (1..m) |j| {\n        dp[j] = dp[j - 1] + grid[0][j];\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (1..n) |i| {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        dp[0] = dp[0] + grid[i][0];\n        for (1..m) |j| {\n            dp[j] = @min(dp[j - 1], dp[j]) + grid[i][j];\n        }\n    }\n    return 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\"\"\"\n    n, m = len(s), len(t)\n    dp = [[0] * (m + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i in range(1, n + 1):\n        dp[i][0] = i\n    for j in range(1, m + 1):\n        dp[0][j] = j\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in range(1, n + 1):\n        for j in range(1, m + 1):\n            if s[i - 1] == t[j - 1]:\n                # \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1\n    return dp[n][m]\n
    edit_distance.cpp
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(string s, string t) {\n    int n = s.length(), m = t.length();\n    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.java
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\n    int n = s.length(), m = t.length();\n    int[][] dp = new int[n + 1][m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (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\n                dp[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\n                dp[i][j] = Math.min(Math.min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.cs
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint EditDistanceDP(string s, string t) {\n    int n = s.Length, m = t.Length;\n    int[,] dp = new int[n + 1, m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i, 0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0, j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i, j] = Math.Min(Math.Min(dp[i, j - 1], dp[i - 1, j]), dp[i - 1, j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n, m];\n}\n
    edit_distance.go
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s string, t string) int {\n    n := len(s)\n    m := len(t)\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, m+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i := 1; i <= n; i++ {\n        dp[i][0] = i\n    }\n    for j := 1; j <= m; j++ {\n        dp[0][j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i <= n; i++ {\n        for j := 1; j <= m; j++ {\n            if s[i-1] == t[j-1] {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = MinInt(MinInt(dp[i][j-1], dp[i-1][j]), dp[i-1][j-1]) + 1\n            }\n        }\n    }\n    return dp[n][m]\n}\n
    edit_distance.swift
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc editDistanceDP(s: String, t: String) -> Int {\n    let n = s.utf8CString.count\n    let m = t.utf8CString.count\n    var dp = Array(repeating: Array(repeating: 0, count: m + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i in stride(from: 1, through: n, by: 1) {\n        dp[i][0] = i\n    }\n    for j in stride(from: 1, through: m, by: 1) {\n        dp[0][j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in stride(from: 1, through: n, by: 1) {\n        for j in stride(from: 1, through: m, by: 1) {\n            if 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\n                dp[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\n                dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1\n            }\n        }\n    }\n    return dp[n][m]\n}\n
    edit_distance.js
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s, t) {\n    const n = s.length,\n        m = t.length;\n    const dp = Array.from({ length: n + 1 }, () => new Array(m + 1).fill(0));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (let j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let j = 1; j <= m; j++) {\n            if (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\n                dp[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\n                dp[i][j] =\n                    Math.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.ts
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction editDistanceDP(s: string, t: string): number {\n    const n = s.length,\n        m = t.length;\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: m + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (let j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let j = 1; j <= m; j++) {\n            if (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\n                dp[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\n                dp[i][j] =\n                    Math.min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return dp[n][m];\n}\n
    edit_distance.dart
    /* \u7f16\u8f91\u8ddd\u79bb\uff1a\u52a8\u6001\u89c4\u5212 */\nint editDistanceDP(String s, String t) {\n  int n = s.length, m = t.length;\n  List<List<int>> dp = List.generate(n + 1, (_) => List.filled(m + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n  for (int i = 1; i <= n; i++) {\n    dp[i][0] = i;\n  }\n  for (int j = 1; j <= m; j++) {\n    dp[0][j] = j;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n  for (int i = 1; i <= n; i++) {\n    for (int j = 1; j <= m; j++) {\n      if (s[i - 1] == t[j - 1]) {\n        // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n        dp[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\n        dp[i][j] = min(min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n      }\n    }\n  }\n  return 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 {\n    let (n, m) = (s.len(), t.len());\n    let mut dp = vec![vec![0; m + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for i in 1..= n {\n        dp[i][0] = i as i32;\n    }\n    for j in 1..m {\n        dp[0][j] = j as i32;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in 1..=n {\n        for j in 1..=m {\n            if 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\n                dp[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\n                dp[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    }\n    dp[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) {\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(m + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int i = 1; i <= n; i++) {\n        dp[i][0] = i;\n    }\n    for (int j = 1; j <= m; j++) {\n        dp[0][j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int j = 1; j <= m; j++) {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = myMin(myMin(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    int res = dp[n][m];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    return 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 {\n    comptime var n = s.len;\n    comptime var m = t.len;\n    var dp = [_][m + 1]i32{[_]i32{0} ** (m + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (1..n + 1) |i| {\n        dp[i][0] = @intCast(i);\n    }\n    for (1..m + 1) |j| {\n        dp[0][j] = @intCast(j);\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (1..n + 1) |i| {\n        for (1..m + 1) |j| {\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[i][j] = @min(@min(dp[i][j - 1], dp[i - 1][j]), dp[i - 1][j - 1]) + 1;\n            }\n        }\n    }\n    return 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\"\"\"\n    n, m = len(s), len(t)\n    dp = [0] * (m + 1)\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in range(1, m + 1):\n        dp[j] = j\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in range(1, n + 1):\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        leftup = dp[0]  # \u6682\u5b58 dp[i-1, j-1]\n        dp[0] += 1\n        # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in range(1, m + 1):\n            temp = dp[j]\n            if s[i - 1] == t[j - 1]:\n                # \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = min(dp[j - 1], dp[j], leftup) + 1\n            leftup = temp  # \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n    return 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) {\n    int n = s.length(), m = t.length();\n    vector<int> dp(m + 1, 0);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n    int n = s.length(), m = t.length();\n    int[] dp = new int[m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (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\n                dp[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\n                dp[j] = Math.min(Math.min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n    int n = s.Length, m = t.Length;\n    int[] dp = new int[m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = Math.Min(Math.Min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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 {\n    n := len(s)\n    m := len(t)\n    dp := make([]int, m+1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j := 1; j <= m; j++ {\n        dp[j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i := 1; i <= n; i++ {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        leftUp := dp[0] // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j := 1; j <= m; j++ {\n            temp := dp[j]\n            if s[i-1] == t[j-1] {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = MinInt(MinInt(dp[j-1], dp[j]), leftUp) + 1\n            }\n            leftUp = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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 {\n    let n = s.utf8CString.count\n    let m = t.utf8CString.count\n    var dp = Array(repeating: 0, count: m + 1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in stride(from: 1, through: m, by: 1) {\n        dp[j] = j\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in stride(from: 1, through: n, by: 1) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        var leftup = dp[0] // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in stride(from: 1, through: m, by: 1) {\n            let temp = dp[j]\n            if 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\n                dp[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\n                dp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1\n            }\n            leftup = temp // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n    const n = s.length,\n        m = t.length;\n    const dp = new Array(m + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        let leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j <= m; j++) {\n            const temp = dp[j];\n            if (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\n                dp[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\n                dp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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 {\n    const n = s.length,\n        m = t.length;\n    const dp = new Array(m + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (let j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (let i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        let leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (let j = 1; j <= m; j++) {\n            const temp = dp[j];\n            if (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\n                dp[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\n                dp[j] = Math.min(dp[j - 1], dp[j], leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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) {\n  int n = s.length, m = t.length;\n  List<int> dp = List.filled(m + 1, 0);\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n  for (int j = 1; j <= m; j++) {\n    dp[j] = j;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n  for (int i = 1; i <= n; i++) {\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n    int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n    dp[0] = i;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n    for (int j = 1; j <= m; j++) {\n      int temp = dp[j];\n      if (s[i - 1] == t[j - 1]) {\n        // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n        dp[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\n        dp[j] = min(min(dp[j - 1], dp[j]), leftup) + 1;\n      }\n      leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n    }\n  }\n  return 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 {\n    let (n, m) = (s.len(), t.len());\n    let mut dp = vec![0; m + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for j in 1..m {\n        dp[j] = j as i32;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for i in 1..=n {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        let mut leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i as i32;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for j in 1..=m {\n            let temp = dp[j];\n            if 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\n                dp[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\n                dp[j] = std::cmp::min(std::cmp::min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    dp[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) {\n    int *dp = calloc(m + 1, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (int j = 1; j <= m; j++) {\n        dp[j] = j;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (int i = 1; i <= n; i++) {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        int leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = i;\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (int j = 1; j <= m; j++) {\n            int temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = myMin(myMin(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    int res = dp[m];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = s.len;\n    comptime var m = t.len;\n    var dp = [_]i32{0} ** (m + 1);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\n    for (1..m + 1) |j| {\n        dp[j] = @intCast(j);\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\n    for (1..n + 1) |i| {\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u5217\n        var leftup = dp[0]; // \u6682\u5b58 dp[i-1, j-1]\n        dp[0] = @intCast(i);\n        // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u5217\n        for (1..m + 1) |j| {\n            var temp = dp[j];\n            if (s[i - 1] == t[j - 1]) {\n                // \u82e5\u4e24\u5b57\u7b26\u76f8\u7b49\uff0c\u5219\u76f4\u63a5\u8df3\u8fc7\u6b64\u4e24\u5b57\u7b26\n                dp[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\n                dp[j] = @min(@min(dp[j - 1], dp[j]), leftup) + 1;\n            }\n            leftup = temp; // \u66f4\u65b0\u4e3a\u4e0b\u4e00\u8f6e\u7684 dp[i-1, j-1]\n        }\n    }\n    return 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\n    if state == n:\n        res[0] += 1\n    # \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices:\n        # \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state + choice > n:\n            continue\n        # \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res)\n        # \u56de\u9000\n\ndef climbing_stairs_backtrack(n: int) -> int:\n    \"\"\"\u722c\u697c\u68af\uff1a\u56de\u6eaf\"\"\"\n    choices = [1, 2]  # \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    state = 0  # \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    res = [0]  # \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res)\n    return 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\n    if (state == n)\n        res[0]++;\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (auto &choice : choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n    vector<int> choices = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0;                // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    vector<int> res = {0};        // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return 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\n    if (state == n)\n        res.set(0, res.get(0) + 1);\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (Integer choice : choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n    List<Integer> choices = Arrays.asList(1, 2); // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    List<Integer> res = new ArrayList<>();\n    res.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return 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\n    if (state == n)\n        res[0]++;\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    foreach (int choice in choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        Backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint ClimbingStairsBacktrack(int n) {\n    List<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    List<int> res = [0]; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    Backtrack(choices, state, n, res);\n    return 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\n    if state == n {\n        res[0] = res[0] + 1\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for _, choice := range choices {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state+choice > n {\n            continue\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state+choice, n, res)\n        // \u56de\u9000\n    }\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\n    choices := []int{1, 2}\n    // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    state := 0\n    res := make([]int, 1)\n    // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    res[0] = 0\n    backtrack(choices, state, n, res)\n    return 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\n    if state == n {\n        res[0] += 1\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for choice in choices {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state + choice > n {\n            continue\n        }\n        backtrack(choices: choices, state: state + choice, n: n, res: &res)\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunc climbingStairsBacktrack(n: Int) -> Int {\n    let choices = [1, 2] // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    let state = 0 // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    var res: [Int] = []\n    res.append(0) // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices: choices, state: state, n: n, res: &res)\n    return 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\n    if (state === n) res.set(0, res.get(0) + 1);\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n) continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n) {\n    const choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    const state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    const res = new Map();\n    res.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return res.get(0);\n}\n
    climbing_stairs_backtrack.ts
    /* \u56de\u6eaf */\nfunction backtrack(\n    choices: number[],\n    state: number,\n    n: number,\n    res: Map<0, any>\n): void {\n    // \u5f53\u722c\u5230\u7b2c n \u9636\u65f6\uff0c\u65b9\u6848\u6570\u91cf\u52a0 1\n    if (state === n) res.set(0, res.get(0) + 1);\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (const choice of choices) {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n) continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfunction climbingStairsBacktrack(n: number): number {\n    const choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    const state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    const res = new Map();\n    res.set(0, 0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(choices, state, n, res);\n    return 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\n  if (state == n) {\n    res[0]++;\n  }\n  // \u904d\u5386\u6240\u6709\u9009\u62e9\n  for (int choice in choices) {\n    // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n    if (state + choice > n) continue;\n    // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n    backtrack(choices, state + choice, n, res);\n    // \u56de\u9000\n  }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n  List<int> choices = [1, 2]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n  int state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n  List<int> res = [];\n  res.add(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n  backtrack(choices, state, n, res);\n  return 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\n    if state == n { res[0] = res[0] + 1; }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for &choice in choices {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if state + choice > n { continue; }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nfn climbing_stairs_backtrack(n: usize) -> i32 {\n    let choices = vec![ 1, 2 ]; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    let state = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    let mut res = Vec::new();\n    res.push(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(&choices, state, n as i32, &mut res);\n    res[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\n    if (state == n)\n        res[0]++;\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (int i = 0; i < len; i++) {\n        int choice = choices[i];\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n)\n            continue;\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res, len);\n        // \u56de\u9000\n    }\n}\n\n/* \u722c\u697c\u68af\uff1a\u56de\u6eaf */\nint climbingStairsBacktrack(int n) {\n    int choices[2] = {1, 2}; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    int state = 0;           // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    int *res = (int *)malloc(sizeof(int));\n    *res = 0; // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    int len = sizeof(choices) / sizeof(int);\n    backtrack(choices, state, n, res, len);\n    int result = *res;\n    free(res);\n    return 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\n    if (state == n) {\n        res.items[0] = res.items[0] + 1;\n    }\n    // \u904d\u5386\u6240\u6709\u9009\u62e9\n    for (choices) |choice| {\n        // \u526a\u679d\uff1a\u4e0d\u5141\u8bb8\u8d8a\u8fc7\u7b2c n \u9636\n        if (state + choice > n) {\n            continue;\n        }\n        // \u5c1d\u8bd5\uff1a\u505a\u51fa\u9009\u62e9\uff0c\u66f4\u65b0\u72b6\u6001\n        backtrack(choices, state + choice, n, res);\n        // \u56de\u9000\n    }\n}\n\n// \u722c\u697c\u68af\uff1a\u56de\u6eaf\nfn climbingStairsBacktrack(n: usize) !i32 {\n    var choices = [_]i32{ 1, 2 }; // \u53ef\u9009\u62e9\u5411\u4e0a\u722c 1 \u9636\u6216 2 \u9636\n    var state: i32 = 0; // \u4ece\u7b2c 0 \u9636\u5f00\u59cb\u722c\n    var res = std.ArrayList(i32).init(std.heap.page_allocator);\n    defer res.deinit();\n    try res.append(0); // \u4f7f\u7528 res[0] \u8bb0\u5f55\u65b9\u6848\u6570\u91cf\n    backtrack(&choices, state, @intCast(n), res);\n    return 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\n    if i == 1 or i == 2:\n        return i\n    # dp[i] = dp[i-1] + dp[i-2]\n    count = dfs(i - 1) + dfs(i - 2)\n    return count\n\ndef climbing_stairs_dfs(n: int) -> int:\n    \"\"\"\u722c\u697c\u68af\uff1a\u641c\u7d22\"\"\"\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = DFS(i - 1) + DFS(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint ClimbingStairsDFS(int n) {\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    count := dfs(i-1) + dfs(i-2)\n    return count\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n int) int {\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i: i - 1) + dfs(i: i - 2)\n    return count\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunc climbingStairsDFS(n: Int) -> Int {\n    dfs(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\n    if (i === 1 || i === 2) return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n) {\n    return 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\n    if (i === 1 || i === 2) return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfunction climbingStairsDFS(n: number): number {\n    return 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\n  if (i == 1 || i == 2) return i;\n  // dp[i] = dp[i-1] + dp[i-2]\n  int count = dfs(i - 1) + dfs(i - 2);\n  return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n  return 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\n    if i == 1 || i == 2 { return i as i32; }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i - 1) + dfs(i - 2);\n    count\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nfn climbing_stairs_dfs(n: usize) -> i32 {\n    dfs(n) \n}\n
    climbing_stairs_dfs.c
    /* \u641c\u7d22 */\nint dfs(int i) {\n    // \u5df2\u77e5 dp[1] \u548c dp[2] \uff0c\u8fd4\u56de\u4e4b\n    if (i == 1 || i == 2)\n        return i;\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n/* \u722c\u697c\u68af\uff1a\u641c\u7d22 */\nint climbingStairsDFS(int n) {\n    return 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\n    if (i == 1 or i == 2) {\n        return @intCast(i);\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    var count = dfs(i - 1) + dfs(i - 2);\n    return count;\n}\n\n// \u722c\u697c\u68af\uff1a\u641c\u7d22\nfn climbingStairsDFS(comptime n: usize) i32 {\n    return 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\u5b50\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\n    if i == 1 or i == 2:\n        return i\n    # \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1:\n        return mem[i]\n    # dp[i] = dp[i-1] + dp[i-2]\n    count = dfs(i - 1, mem) + dfs(i - 2, mem)\n    # \u8bb0\u5f55 dp[i]\n    mem[i] = count\n    return count\n\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\n    mem = [-1] * (n + 1)\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    vector<int> mem(n + 1, -1);\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    int[] mem = new int[n + 1];\n    Arrays.fill(mem, -1);\n    return 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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = DFS(i - 1, mem) + DFS(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    int[] mem = new int[n + 1];\n    Array.Fill(mem, -1);\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1 {\n        return mem[i]\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    count := dfsMem(i-1, mem) + dfsMem(i-2, mem)\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count\n    return count\n}\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\n    mem := make([]int, n+1)\n    for i := range mem {\n        mem[i] = -1\n    }\n    return 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\n    if i == 1 || i == 2 {\n        return i\n    }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1 {\n        return mem[i]\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i: i - 1, mem: &mem) + dfs(i: i - 2, mem: &mem)\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count\n    return count\n}\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\n    var mem = Array(repeating: -1, count: n + 1)\n    return 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\n    if (i === 1 || i === 2) return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1) return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    const mem = new Array(n + 1).fill(-1);\n    return 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\n    if (i === 1 || i === 2) return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1) return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    const count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    const mem = new Array(n + 1).fill(-1);\n    return 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\n  if (i == 1 || i == 2) return i;\n  // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n  if (mem[i] != -1) return mem[i];\n  // dp[i] = dp[i-1] + dp[i-2]\n  int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n  // \u8bb0\u5f55 dp[i]\n  mem[i] = count;\n  return count;\n}\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\n  List<int> mem = List.filled(n + 1, -1);\n  return 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\n    if i == 1 || i == 2 { return i as i32; }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if mem[i] != -1 { return mem[i]; }\n    // dp[i] = dp[i-1] + dp[i-2]\n    let count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    count\n}\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\n    let mut mem = vec![-1; n + 1];\n    dfs(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\n    if (i == 1 || i == 2)\n        return i;\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1)\n        return mem[i];\n    // dp[i] = dp[i-1] + dp[i-2]\n    int count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    int *mem = (int *)malloc((n + 1) * sizeof(int));\n    for (int i = 0; i <= n; i++) {\n        mem[i] = -1;\n    }\n    int result = dfs(n, mem);\n    free(mem);\n    return 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\n    if (i == 1 or i == 2) {\n        return @intCast(i);\n    }\n    // \u82e5\u5b58\u5728\u8bb0\u5f55 dp[i] \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\u4e4b\n    if (mem[i] != -1) {\n        return mem[i];\n    }\n    // dp[i] = dp[i-1] + dp[i-2]\n    var count = dfs(i - 1, mem) + dfs(i - 2, mem);\n    // \u8bb0\u5f55 dp[i]\n    mem[i] = count;\n    return count;\n}\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\n    var mem = [_]i32{ -1 } ** (n + 1);\n    return 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\"\"\"\n    if n == 1 or n == 2:\n        return n\n    # \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp = [0] * (n + 1)\n    # \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[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\n    for i in range(3, n + 1):\n        dp[i] = dp[i - 1] + dp[i - 2]\n    return dp[n]\n
    climbing_stairs_dp.cpp
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    vector<int> dp(n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.java
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.cs
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint ClimbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int[] dp = new int[n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.go
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n int) int {\n    if n == 1 || n == 2 {\n        return n\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    dp := make([]int, n+1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1\n    dp[2] = 2\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        dp[i] = dp[i-1] + dp[i-2]\n    }\n    return dp[n]\n}\n
    climbing_stairs_dp.swift
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc climbingStairsDP(n: Int) -> Int {\n    if n == 1 || n == 2 {\n        return n\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = Array(repeating: 0, count: n + 1)\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1\n    dp[2] = 2\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in stride(from: 3, through: n, by: 1) {\n        dp[i] = dp[i - 1] + dp[i - 2]\n    }\n    return dp[n]\n}\n
    climbing_stairs_dp.js
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n) {\n    if (n === 1 || n === 2) return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1).fill(-1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.ts
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDP(n: number): number {\n    if (n === 1 || n === 2) return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    const dp = new Array(n + 1).fill(-1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (let i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return dp[n];\n}\n
    climbing_stairs_dp.dart
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n  if (n == 1 || n == 2) return n;\n  // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n  List<int> dp = List.filled(n + 1, 0);\n  // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n  dp[1] = 1;\n  dp[2] = 2;\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n  for (int i = 3; i <= n; i++) {\n    dp[i] = dp[i - 1] + dp[i - 2];\n  }\n  return 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\n    if n == 1 || n == 2 { return n as i32; }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    let mut dp = vec![-1; n + 1];\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i in 3..=n {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    dp[n]\n}\n
    climbing_stairs_dp.c
    /* \u722c\u697c\u68af\uff1a\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDP(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    int *dp = (int *)malloc((n + 1) * sizeof(int));\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (int i = 3; i <= n; i++) {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    int result = dp[n];\n    free(dp);\n    return 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\n    if (n == 1 or n == 2) {\n        return @intCast(n);\n    }\n    // \u521d\u59cb\u5316 dp \u8868\uff0c\u7528\u4e8e\u5b58\u50a8\u5b50\u95ee\u9898\u7684\u89e3\n    var dp = [_]i32{-1} ** (n + 1);\n    // \u521d\u59cb\u72b6\u6001\uff1a\u9884\u8bbe\u6700\u5c0f\u5b50\u95ee\u9898\u7684\u89e3\n    dp[1] = 1;\n    dp[2] = 2;\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for (3..n + 1) |i| {\n        dp[i] = dp[i - 1] + dp[i - 2];\n    }\n    return 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\"\"\"\n    if n == 1 or n == 2:\n        return n\n    a, b = 1, 2\n    for _ in range(3, n + 1):\n        a, b = b, a + b\n    return b\n
    climbing_stairs_dp.cpp
    /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return n\n    }\n    a, b := 1, 2\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u4ece\u8f83\u5c0f\u5b50\u95ee\u9898\u9010\u6b65\u6c42\u89e3\u8f83\u5927\u5b50\u95ee\u9898\n    for i := 3; i <= n; i++ {\n        a, b = b, a+b\n    }\n    return 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 {\n    if n == 1 || n == 2 {\n        return n\n    }\n    var a = 1\n    var b = 2\n    for _ in stride(from: 3, through: n, by: 1) {\n        (a, b) = (b, a + b)\n    }\n    return b\n}\n
    climbing_stairs_dp.js
    /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction climbingStairsDPComp(n) {\n    if (n === 1 || n === 2) return n;\n    let a = 1,\n        b = 2;\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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 {\n    if (n === 1 || n === 2) return n;\n    let a = 1,\n        b = 2;\n    for (let i = 3; i <= n; i++) {\n        const tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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) {\n  if (n == 1 || n == 2) return n;\n  int a = 1, b = 2;\n  for (int i = 3; i <= n; i++) {\n    int tmp = b;\n    b = a + b;\n    a = tmp;\n  }\n  return 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 {\n    if n == 1 || n == 2 { return n as i32; }\n    let (mut a, mut b) = (1, 2);\n    for _ in 3..=n {\n        let tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    b\n}\n
    climbing_stairs_dp.c
    /* \u722c\u697c\u68af\uff1a\u7a7a\u95f4\u4f18\u5316\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nint climbingStairsDPComp(int n) {\n    if (n == 1 || n == 2)\n        return n;\n    int a = 1, b = 2;\n    for (int i = 3; i <= n; i++) {\n        int tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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 {\n    if (n == 1 or n == 2) {\n        return @intCast(n);\n    }\n    var a: i32 = 1;\n    var b: i32 = 2;\n    for (3..n + 1) |_| {\n        var tmp = b;\n        b = a + b;\n        a = tmp;\n    }\n    return 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\n    if i == 0 or c == 0:\n        return 0\n    # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c:\n        return knapsack_dfs(wgt, val, i - 1, c)\n    # \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    no = knapsack_dfs(wgt, val, i - 1, c)\n    yes = 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\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = knapsackDFS(wgt, val, i - 1, c);\n    int 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\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = knapsackDFS(wgt, val, i - 1, c);\n    int 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\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (weight[i - 1] > c) {\n        return KnapsackDFS(weight, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = KnapsackDFS(weight, val, i - 1, c);\n    int 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\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i-1] > c {\n        return knapsackDFS(wgt, val, i-1, c)\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    no := knapsackDFS(wgt, val, i-1, c)\n    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\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c {\n        return 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\n    let no = knapsackDFS(wgt: wgt, val: val, i: i - 1, c: c)\n    let 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\n    return 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    const no = knapsackDFS(wgt, val, i - 1, c);\n    const 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\n    return Math.max(no, yes);\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u66b4\u529b\u641c\u7d22 */\nfunction knapsackDFS(\n    wgt: Array<number>,\n    val: Array<number>,\n    i: number,\n    c: 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    const no = knapsackDFS(wgt, val, i - 1, c);\n    const 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\n    return 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\n  if (i == 0 || c == 0) {\n    return 0;\n  }\n  // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n  if (wgt[i - 1] > c) {\n    return knapsackDFS(wgt, val, i - 1, c);\n  }\n  // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n  int no = knapsackDFS(wgt, val, i - 1, c);\n  int 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\n  return 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\n    if i == 0 || c == 0 {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c as i32 {\n        return 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\n    let no = knapsack_dfs(wgt, val, i - 1, c);\n    let 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\n    std::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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    int no = knapsackDFS(wgt, val, i - 1, c);\n    int 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\n    return 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\n    if (i == 0 or c == 0) {\n        return 0;\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return knapsackDFS(wgt, val, i - 1, c);\n    }\n    // \u8ba1\u7b97\u4e0d\u653e\u5165\u548c\u653e\u5165\u7269\u54c1 i \u7684\u6700\u5927\u4ef7\u503c\n    var no = knapsackDFS(wgt, val, i - 1, c);\n    var 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\n    return @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(\n    wgt: 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\n    if i == 0 or c == 0:\n        return 0\n    # \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1:\n        return mem[i][c]\n    # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c:\n        return 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\n    no = knapsack_dfs_mem(wgt, val, mem, i - 1, c)\n    yes = 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\n    mem[i][c] = max(no, yes)\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    int no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    int 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\n    mem[i][c] = max(no, yes);\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    int no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    int 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\n    mem[i][c] = Math.max(no, yes);\n    return 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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (weight[i - 1] > c) {\n        return 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\n    int no = KnapsackDFSMem(weight, val, mem, i - 1, c);\n    int 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\n    mem[i][c] = Math.Max(no, yes);\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1 {\n        return mem[i][c]\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i-1] > c {\n        return 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\n    no := knapsackDFSMem(wgt, val, mem, i-1, c)\n    yes := 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\n    mem[i][c] = int(math.Max(float64(no), float64(yes)))\n    return 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\n    if i == 0 || c == 0 {\n        return 0\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1 {\n        return mem[i][c]\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c {\n        return 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\n    let no = knapsackDFSMem(wgt: wgt, val: val, mem: &mem, i: i - 1, c: c)\n    let 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\n    mem[i][c] = max(no, yes)\n    return 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] !== -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    const no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    const yes =\n        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\n    mem[i][c] = Math.max(no, yes);\n    return mem[i][c];\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nfunction knapsackDFSMem(\n    wgt: Array<number>,\n    val: Array<number>,\n    mem: Array<Array<number>>,\n    i: number,\n    c: 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\n    if (i === 0 || c === 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] !== -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    const no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    const yes =\n        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\n    mem[i][c] = Math.max(no, yes);\n    return mem[i][c];\n}\n
    knapsack.dart
    /* 0-1 \u80cc\u5305\uff1a\u8bb0\u5fc6\u5316\u641c\u7d22 */\nint knapsackDFSMem(\n  List<int> wgt,\n  List<int> val,\n  List<List<int>> mem,\n  int i,\n  int 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\n  if (i == 0 || c == 0) {\n    return 0;\n  }\n  // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n  if (mem[i][c] != -1) {\n    return mem[i][c];\n  }\n  // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n  if (wgt[i - 1] > c) {\n    return 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\n  int no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n  int 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\n  mem[i][c] = max(no, yes);\n  return 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\n    if i == 0 || c == 0 {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if mem[i][c] != -1 {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if wgt[i - 1] > c as i32 {\n        return 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\n    let no = knapsack_dfs_mem(wgt, val, mem, i - 1, c);\n    let 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\n    mem[i][c] = std::cmp::max(no, yes);\n    mem[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\n    if (i == 0 || c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    int no = knapsackDFSMem(wgt, val, memCols, mem, i - 1, c);\n    int 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\n    mem[i][c] = myMax(no, yes);\n    return 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\n    if (i == 0 or c == 0) {\n        return 0;\n    }\n    // \u82e5\u5df2\u6709\u8bb0\u5f55\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (mem[i][c] != -1) {\n        return mem[i][c];\n    }\n    // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u53ea\u80fd\u9009\u62e9\u4e0d\u653e\u5165\u80cc\u5305\n    if (wgt[i - 1] > c) {\n        return 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\n    var no = knapsackDFSMem(wgt, val, mem, i - 1, c);\n    var 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\n    mem[i][c] = @max(no, yes);\n    return 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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (cap + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        for c in range(1, cap + 1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    knapsack.java
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint knapsackDP(int[] wgt, int[] val, int cap) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    knapsack.cs
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nint KnapsackDP(int[] weight, int[] val, int cap) {\n    int n = weight.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (weight[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i, c] = Math.Max(dp[i - 1, c - weight[i - 1]] + val[i - 1], dp[i - 1, c]);\n            }\n        }\n    }\n    return dp[n, cap];\n}\n
    knapsack.go
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc knapsackDP(wgt, val []int, cap int) int {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, cap+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        for c := 1; c <= cap; c++ {\n            if wgt[i-1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i-1][c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for c in stride(from: 1, through: cap, by: 1) {\n            if wgt[i - 1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return dp[n][cap]\n}\n
    knapsack.js
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(wgt, val, cap) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array(n + 1)\n        .fill(0)\n        .map(() => Array(cap + 1).fill(0));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i - 1][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDP(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: cap + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i - 1][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int c = 1; c <= cap; c++) {\n      if (wgt[i - 1] > c) {\n        // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n        dp[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\n        dp[i][c] = max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; cap + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for c in 1..=cap {\n            if wgt[i - 1] > c as i32 {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = std::cmp::max(dp[i - 1][c], dp[i - 1][c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    dp[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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(cap + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = myMax(dp[i - 1][c], dp[i - 1][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[n][cap];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    return 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 {\n    comptime var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..cap + 1) |c| {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = @max(dp[i - 1][c], dp[i - 1][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * (cap + 1)\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u5012\u5e8f\u904d\u5386\n        for c in range(cap, 0, -1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(cap + 1, 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = weight.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c > 0; c--) {\n            if (weight[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.Max(dp[c], dp[c - weight[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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 {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, cap+1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        // \u5012\u5e8f\u904d\u5386\n        for c := cap; c >= 1; c-- {\n            if wgt[i-1] <= c {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: cap + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        // \u5012\u5e8f\u904d\u5386\n        for c in stride(from: cap, through: 1, by: -1) {\n            if wgt[i - 1] <= c {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return 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) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array(cap + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (let c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[cap];\n}\n
    knapsack.ts
    /* 0-1 \u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction knapsackDPComp(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array(cap + 1).fill(0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (let c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(cap + 1, 0);\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    // \u5012\u5e8f\u904d\u5386\n    for (int c = cap; c >= 1; c--) {\n      if (wgt[i - 1] <= c) {\n        // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n        dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        // \u5012\u5e8f\u904d\u5386\n        for c in (1..=cap).rev() {\n            if wgt[i - 1] <= c as i32 {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    dp[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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(cap + 1, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        // \u5012\u5e8f\u904d\u5386\n        for (int c = cap; c >= 1; c--) {\n            if (wgt[i - 1] <= c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[cap];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (cap + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        // \u5012\u5e8f\u904d\u5386\n        var c = cap;\n        while (c > 0) : (c -= 1) {\n            if (wgt[i - 1] < c) {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\u641c\u7d22\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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (cap + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        for c in range(1, cap + 1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(cap + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i, c] = Math.Max(dp[i - 1, c], dp[i, c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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 {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, cap+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        for c := 1; c <= cap; c++ {\n            if wgt[i-1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = int(math.Max(float64(dp[i-1][c]), float64(dp[i][c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: cap + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for c in stride(from: 1, through: cap, by: 1) {\n            if wgt[i - 1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return dp[n][cap]\n}\n
    unbounded_knapsack.js
    /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(wgt, val, cap) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: cap + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return dp[n][cap];\n}\n
    unbounded_knapsack.ts
    /* \u5b8c\u5168\u80cc\u5305\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDP(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: cap + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = Math.max(\n                    dp[i - 1][c],\n                    dp[i][c - wgt[i - 1]] + val[i - 1]\n                );\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(cap + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int c = 1; c <= cap; c++) {\n      if (wgt[i - 1] > c) {\n        // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n        dp[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\n        dp[i][c] = max(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; cap + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for c in 1..=cap {\n            if wgt[i - 1] > c as i32 {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = std::cmp::max(dp[i - 1][c], dp[i][c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(cap + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = myMax(dp[i - 1][c], dp[i][c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[n][cap];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    return 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 {\n    comptime var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][cap + 1]i32{[_]i32{0} ** (cap + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..cap + 1) |c| {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[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\n                dp[i][c] = @max(dp[i - 1][c], dp[i][c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(wgt)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * (cap + 1)\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u6b63\u5e8f\u904d\u5386\n        for c in range(1, cap + 1):\n            if wgt[i - 1] > c:\n                # \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n    return 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) {\n    int n = wgt.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(cap + 1, 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n    int n = wgt.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.Max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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 {\n    n := len(wgt)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, cap+1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        for c := 1; c <= cap; c++ {\n            if wgt[i-1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = int(math.Max(float64(dp[c]), float64(dp[c-wgt[i-1]]+val[i-1])))\n            }\n        }\n    }\n    return 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 {\n    let n = wgt.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: cap + 1)\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for c in stride(from: 1, through: cap, by: 1) {\n            if wgt[i - 1] > c {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1])\n            }\n        }\n    }\n    return 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) {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: cap + 1 }, () => 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return dp[cap];\n}\n
    unbounded_knapsack.ts
    /* \u5b8c\u5168\u80cc\u5305\uff1a\u72b6\u6001\u538b\u7f29\u540e\u7684\u52a8\u6001\u89c4\u5212 */\nfunction unboundedKnapsackDPComp(\n    wgt: Array<number>,\n    val: Array<number>,\n    cap: number\n): number {\n    const n = wgt.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: cap + 1 }, () => 0);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = Math.max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    return 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) {\n  int n = wgt.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(cap + 1, 0);\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int c = 1; c <= cap; c++) {\n      if (wgt[i - 1] > c) {\n        // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n        dp[c] = dp[c];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n        dp[c] = max(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n      }\n    }\n  }\n  return 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 {\n    let n = wgt.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; cap + 1];\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for c in 1..=cap {\n            if wgt[i - 1] > c as i32 {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = std::cmp::max(dp[c], dp[c - wgt[i - 1] as usize] + val[i - 1]);\n            }\n        }\n    }\n    dp[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) {\n    int n = wgtSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(cap + 1, sizeof(int));\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int c = 1; c <= cap; c++) {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = myMax(dp[c], dp[c - wgt[i - 1]] + val[i - 1]);\n            }\n        }\n    }\n    int res = dp[cap];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = wgt.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (cap + 1);\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..cap + 1) |c| {\n            if (wgt[i - 1] > c) {\n                // \u82e5\u8d85\u8fc7\u80cc\u5305\u5bb9\u91cf\uff0c\u5219\u4e0d\u9009\u7269\u54c1 i\n                dp[c] = dp[c];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u7269\u54c1 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5927\u503c\n                dp[c] = @max(dp[c], dp[c - @as(usize, @intCast(wgt[i - 1]))] + val[i - 1]);\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(coins)\n    MAX = amt + 1\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (amt + 1) for _ in range(n + 1)]\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a in range(1, amt + 1):\n        dp[0][a] = MAX\n    # \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in range(1, n + 1):\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\n    return 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) {\n    int n = coins.size();\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][amt + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, amt + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0, a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i, a] = Math.Min(dp[i - 1, a], dp[i, a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    max := amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, amt+1)\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a := 1; a <= amt; a++ {\n        dp[0][a] = max\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i <= n; i++ {\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = int(math.Min(float64(dp[i-1][a]), float64(dp[i][a-coins[i-1]]+1)))\n            }\n        }\n    }\n    if dp[n][amt] != max {\n        return dp[n][amt]\n    }\n    return -1\n}\n
    coin_change.swift
    /* \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212 */\nfunc coinChangeDP(coins: [Int], amt: Int) -> Int {\n    let n = coins.count\n    let MAX = amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a in stride(from: 1, through: amt, by: 1) {\n        dp[0][a] = MAX\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1)\n            }\n        }\n    }\n    return 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) {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (let a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = Math.min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  int MAX = amt + 1;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n  for (int a = 1; a <= amt; a++) {\n    dp[0][a] = MAX;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[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\n        dp[i][a] = min(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    let max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; amt + 1]; n + 1];\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for a in 1..= amt {\n        dp[0][a] = max;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = std::cmp::min(dp[i - 1][a], dp[i][a - coins[i - 1] as usize] + 1);\n            }\n        }\n    }\n    if 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) {\n    int n = coinsSize;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(amt + 1, sizeof(int));\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (int a = 1; a <= amt; a++) {\n        dp[0][a] = MAX;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = myMin(dp[i - 1][a], dp[i][a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    int res = dp[n][amt] != MAX ? dp[n][amt] : -1;\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    free(dp);\n    return res;\n}\n
    coin_change.zig
    // \u96f6\u94b1\u5151\u6362\uff1a\u52a8\u6001\u89c4\u5212\nfn coinChangeDP(comptime coins: []i32, comptime amt: usize) i32 {\n    comptime var n = coins.len;\n    comptime var max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u9996\u884c\u9996\u5217\n    for (1..amt + 1) |a| {\n        dp[0][a] = max;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = @min(dp[i - 1][a], dp[i][a - @as(usize, @intCast(coins[i - 1]))] + 1);\n            }\n        }\n    }\n    if (dp[n][amt] != max) {\n        return @intCast(dp[n][amt]);\n    } else {\n        return -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\"\"\"\n    n = len(coins)\n    MAX = amt + 1\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [MAX] * (amt + 1)\n    dp[0] = 0\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u6b63\u5e8f\u904d\u5386\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\n    return 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) {\n    int n = coins.size();\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(amt + 1, MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    Arrays.fill(dp, MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    Array.Fill(dp, MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.Min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    max := amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, amt+1)\n    for i := 1; i <= amt; i++ {\n        dp[i] = max\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        // \u5012\u5e8f\u904d\u5386\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = int(math.Min(float64(dp[a]), float64(dp[a-coins[i-1]]+1)))\n            }\n        }\n    }\n    if dp[amt] != max {\n        return dp[amt]\n    }\n    return -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 {\n    let n = coins.count\n    let MAX = amt + 1\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: MAX, count: amt + 1)\n    dp[0] = 0\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1)\n            }\n        }\n    }\n    return 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) {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    const MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => MAX);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = Math.min(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  int MAX = amt + 1;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(amt + 1, MAX);\n  dp[0] = 0;\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[a] = dp[a];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n        dp[a] = min(dp[a], dp[a - coins[i - 1]] + 1);\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    let max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; amt + 1];\n    dp.fill(max);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = std::cmp::min(dp[a], dp[a - coins[i - 1] as usize] + 1);\n            }\n        }\n    }\n    if 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) {\n    int n = coinsSize;\n    int MAX = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(amt + 1, sizeof(int));\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = myMin(dp[a], dp[a - coins[i - 1]] + 1);\n            }\n        }\n    }\n    int res = dp[amt] != MAX ? dp[amt] : -1;\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = coins.len;\n    comptime var max = amt + 1;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (amt + 1);\n    @memset(&dp, max);\n    dp[0] = 0;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = @min(dp[a], dp[a - @as(usize, @intCast(coins[i - 1]))] + 1);\n            }\n        }\n    }\n    if (dp[amt] != max) {\n        return @intCast(dp[amt]);\n    } else {\n        return -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\"\"\"\n    n = len(coins)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [[0] * (amt + 1) for _ in range(n + 1)]\n    # \u521d\u59cb\u5316\u9996\u5217\n    for i in range(n + 1):\n        dp[i][0] = 1\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\n    return 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) {\n    int n = coins.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<vector<int>> dp(n + 1, vector<int>(amt + 1, 0));\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[][] dp = new int[n + 1][amt + 1];\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[,] dp = new int[n + 1, amt + 1];\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i, 0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i, a] = dp[i - 1, a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i, a] = dp[i - 1, a] + dp[i, a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([][]int, n+1)\n    for i := 0; i <= n; i++ {\n        dp[i] = make([]int, amt+1)\n    }\n    // \u521d\u59cb\u5316\u9996\u5217\n    for i := 0; i <= n; i++ {\n        dp[i][0] = 1\n    }\n    // \u72b6\u6001\u8f6c\u79fb\uff1a\u5176\u4f59\u884c\u548c\u5217\n    for i := 1; i <= n; i++ {\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i-1][a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i-1][a] + dp[i][a-coins[i-1]]\n            }\n        }\n    }\n    return 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 {\n    let n = coins.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: Array(repeating: 0, count: amt + 1), count: n + 1)\n    // \u521d\u59cb\u5316\u9996\u5217\n    for i in stride(from: 0, through: n, by: 1) {\n        dp[i][0] = 1\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]]\n            }\n        }\n    }\n    return dp[n][amt]\n}\n
    coin_change_ii.js
    /* \u96f6\u94b1\u5151\u6362 II\uff1a\u52a8\u6001\u89c4\u5212 */\nfunction coinChangeIIDP(coins, amt) {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (let i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: n + 1 }, () =>\n        Array.from({ length: amt + 1 }, () => 0)\n    );\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (let i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<List<int>> dp = List.generate(n + 1, (index) => List.filled(amt + 1, 0));\n  // \u521d\u59cb\u5316\u9996\u5217\n  for (int i = 0; i <= n; i++) {\n    dp[i][0] = 1;\n  }\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[i][a] = dp[i - 1][a];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n        dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![vec![0; amt + 1]; n + 1];\n    // \u521d\u59cb\u5316\u9996\u5217\n    for i in 0..= n {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1] as usize];\n            }\n        }\n    }\n    dp[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) {\n    int n = coinsSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int **dp = malloc((n + 1) * sizeof(int *));\n    for (int i = 0; i <= n; i++) {\n        dp[i] = calloc(amt + 1, sizeof(int));\n    }\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (int i = 0; i <= n; i++) {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[i][a] = dp[i - 1][a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[i][a] = dp[i - 1][a] + dp[i][a - coins[i - 1]];\n            }\n        }\n    }\n    int res = dp[n][amt];\n    // \u91ca\u653e\u5185\u5b58\n    for (int i = 0; i <= n; i++) {\n        free(dp[i]);\n    }\n    free(dp);\n    return 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 {\n    comptime var n = coins.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_][amt + 1]i32{[_]i32{0} ** (amt + 1)} ** (n + 1);\n    // \u521d\u59cb\u5316\u9996\u5217\n    for (0..n + 1) |i| {\n        dp[i][0] = 1;\n    }\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[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\n                dp[i][a] = dp[i - 1][a] + dp[i][a - @as(usize, @intCast(coins[i - 1]))];\n            }\n        }\n    }\n    return 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\"\"\"\n    n = len(coins)\n    # \u521d\u59cb\u5316 dp \u8868\n    dp = [0] * (amt + 1)\n    dp[0] = 1\n    # \u72b6\u6001\u8f6c\u79fb\n    for i in range(1, n + 1):\n        # \u6b63\u5e8f\u904d\u5386\n        for a in range(1, amt + 1):\n            if coins[i - 1] > a:\n                # \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            else:\n                # \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]]\n    return 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) {\n    int n = coins.size();\n    // \u521d\u59cb\u5316 dp \u8868\n    vector<int> dp(amt + 1, 0);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n    int n = coins.Length;\n    // \u521d\u59cb\u5316 dp \u8868\n    int[] dp = new int[amt + 1];\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    n := len(coins)\n    // \u521d\u59cb\u5316 dp \u8868\n    dp := make([]int, amt+1)\n    dp[0] = 1\n    // \u72b6\u6001\u8f6c\u79fb\n    for i := 1; i <= n; i++ {\n        // \u5012\u5e8f\u904d\u5386\n        for a := 1; a <= amt; a++ {\n            if coins[i-1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a-coins[i-1]]\n            }\n        }\n    }\n    return 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 {\n    let n = coins.count\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = Array(repeating: 0, count: amt + 1)\n    dp[0] = 1\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in stride(from: 1, through: n, by: 1) {\n        for a in stride(from: 1, through: amt, by: 1) {\n            if coins[i - 1] > a {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a]\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]]\n            }\n        }\n    }\n    return 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) {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => 0);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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 {\n    const n = coins.length;\n    // \u521d\u59cb\u5316 dp \u8868\n    const dp = Array.from({ length: amt + 1 }, () => 0);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (let i = 1; i <= n; i++) {\n        for (let a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    return 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) {\n  int n = coins.length;\n  // \u521d\u59cb\u5316 dp \u8868\n  List<int> dp = List.filled(amt + 1, 0);\n  dp[0] = 1;\n  // \u72b6\u6001\u8f6c\u79fb\n  for (int i = 1; i <= n; i++) {\n    for (int a = 1; a <= amt; a++) {\n      if (coins[i - 1] > a) {\n        // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n        dp[a] = dp[a];\n      } else {\n        // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n        dp[a] = dp[a] + dp[a - coins[i - 1]];\n      }\n    }\n  }\n  return 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 {\n    let n = coins.len();\n    // \u521d\u59cb\u5316 dp \u8868\n    let mut dp = vec![0; amt + 1];\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for i in 1..=n {\n        for a in 1..=amt {\n            if coins[i - 1] > a as i32 {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = dp[a] + dp[a - coins[i - 1] as usize];\n            }\n        }\n    }\n    dp[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) {\n    int n = coinsSize;\n    // \u521d\u59cb\u5316 dp \u8868\n    int *dp = calloc(amt + 1, sizeof(int));\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (int i = 1; i <= n; i++) {\n        for (int a = 1; a <= amt; a++) {\n            if (coins[i - 1] > a) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u4e4b\u548c\n                dp[a] = dp[a] + dp[a - coins[i - 1]];\n            }\n        }\n    }\n    int res = dp[amt];\n    // \u91ca\u653e\u5185\u5b58\n    free(dp);\n    return 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 {\n    comptime var n = coins.len;\n    // \u521d\u59cb\u5316 dp \u8868\n    var dp = [_]i32{0} ** (amt + 1);\n    dp[0] = 1;\n    // \u72b6\u6001\u8f6c\u79fb\n    for (1..n + 1) |i| {\n        for (1..amt + 1) |a| {\n            if (coins[i - 1] > @as(i32, @intCast(a))) {\n                // \u82e5\u8d85\u8fc7\u76ee\u6807\u91d1\u989d\uff0c\u5219\u4e0d\u9009\u786c\u5e01 i\n                dp[a] = dp[a];\n            } else {\n                // \u4e0d\u9009\u548c\u9009\u786c\u5e01 i \u8fd9\u4e24\u79cd\u65b9\u6848\u7684\u8f83\u5c0f\u503c\n                dp[a] = dp[a] + dp[a - @as(usize, @intCast(coins[i - 1]))];\n            }\n        }\n    }\n    return 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\u300a\u738b\u8005\u8363\u8000\u300b\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\u7684\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\"\"\"\n\n    def __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\n        self.vertices: list[int] = []\n        # \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n        self.adj_mat: list[list[int]] = []\n        # \u6dfb\u52a0\u9876\u70b9\n        for val in vertices:\n            self.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\n        for e in edges:\n            self.add_edge(e[0], e[1])\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\n        return len(self.vertices)\n\n    def add_vertex(self, val: int):\n        \"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\n        n = self.size()\n        # \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        self.vertices.append(val)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        new_row = [0] * n\n        self.adj_mat.append(new_row)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for row in self.adj_mat:\n            row.append(0)\n\n    def remove_vertex(self, index: int):\n        \"\"\"\u5220\u9664\u9876\u70b9\"\"\"\n        if index >= self.size():\n            raise IndexError()\n        # \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        self.vertices.pop(index)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        self.adj_mat.pop(index)\n        # \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for row in self.adj_mat:\n            row.pop(index)\n\n    def 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\n        if i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\n            raise 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)\n        self.adj_mat[i][j] = 1\n        self.adj_mat[j][i] = 1\n\n    def 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\n        if i < 0 or j < 0 or i >= self.size() or j >= self.size() or i == j:\n            raise IndexError()\n        self.adj_mat[i][j] = 0\n        self.adj_mat[j][i] = 0\n\n    def print(self):\n        \"\"\"\u6253\u5370\u90bb\u63a5\u77e9\u9635\"\"\"\n        print(\"\u9876\u70b9\u5217\u8868 =\", self.vertices)\n        print(\"\u90bb\u63a5\u77e9\u9635 =\")\n        print_matrix(self.adj_mat)\n
    graph_adjacency_matrix.cpp
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\n    vector<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\n    vector<vector<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    GraphAdjMat(const vector<int> &vertices, const vector<vector<int>> &edges) {\n        // \u6dfb\u52a0\u9876\u70b9\n        for (int val : vertices) {\n            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\n        for (const vector<int> &edge : edges) {\n            addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int size() const {\n        return vertices.size();\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    void addVertex(int val) {\n        int n = size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.push_back(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        adjMat.emplace_back(vector<int>(n, 0));\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (vector<int> &row : adjMat) {\n            row.push_back(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    void removeVertex(int index) {\n        if (index >= size()) {\n            throw out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.erase(vertices.begin() + index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.erase(adjMat.begin() + index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (vector<int> &row : adjMat) {\n            row.erase(row.begin() + index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    void addEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n            throw 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)\n        adjMat[i][j] = 1;\n        adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    void removeEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n            throw out_of_range(\"\u9876\u70b9\u4e0d\u5b58\u5728\");\n        }\n        adjMat[i][j] = 0;\n        adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    void print() {\n        cout << \"\u9876\u70b9\u5217\u8868 = \";\n        printVector(vertices);\n        cout << \"\u90bb\u63a5\u77e9\u9635 =\" << endl;\n        printVectorMatrix(adjMat);\n    }\n};\n
    graph_adjacency_matrix.java
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\n    List<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\n    List<List<Integer>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public GraphAdjMat(int[] vertices, int[][] edges) {\n        this.vertices = new ArrayList<>();\n        this.adjMat = new ArrayList<>();\n        // \u6dfb\u52a0\u9876\u70b9\n        for (int val : vertices) {\n            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\n        for (int[] e : edges) {\n            addEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    public int size() {\n        return vertices.size();\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void addVertex(int val) {\n        int n = size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.add(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        List<Integer> newRow = new ArrayList<>(n);\n        for (int j = 0; j < n; j++) {\n            newRow.add(0);\n        }\n        adjMat.add(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (List<Integer> row : adjMat) {\n            row.add(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void removeVertex(int index) {\n        if (index >= size())\n            throw new IndexOutOfBoundsException();\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (List<Integer> row : adjMat) {\n            row.remove(index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void addEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\n            throw 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)\n        adjMat.get(i).set(j, 1);\n        adjMat.get(j).set(i, 1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void removeEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= size() || j >= size() || i == j)\n            throw new IndexOutOfBoundsException();\n        adjMat.get(i).set(j, 0);\n        adjMat.get(j).set(i, 0);\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    public void print() {\n        System.out.print(\"\u9876\u70b9\u5217\u8868 = \");\n        System.out.println(vertices);\n        System.out.println(\"\u90bb\u63a5\u77e9\u9635 =\");\n        PrintUtil.printMatrix(adjMat);\n    }\n}\n
    graph_adjacency_matrix.cs
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjMat {\n    List<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\n    List<List<int>> adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u51fd\u6570 */\n    public GraphAdjMat(int[] vertices, int[][] edges) {\n        this.vertices = [];\n        this.adjMat = [];\n        // \u6dfb\u52a0\u9876\u70b9\n        foreach (int val in vertices) {\n            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\n        foreach (int[] e in edges) {\n            AddEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int Size() {\n        return vertices.Count;\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void AddVertex(int val) {\n        int n = Size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.Add(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        List<int> newRow = new(n);\n        for (int j = 0; j < n; j++) {\n            newRow.Add(0);\n        }\n        adjMat.Add(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        foreach (List<int> row in adjMat) {\n            row.Add(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void RemoveVertex(int index) {\n        if (index >= Size())\n            throw new IndexOutOfRangeException();\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.RemoveAt(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.RemoveAt(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        foreach (List<int> row in adjMat) {\n            row.RemoveAt(index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void AddEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\n            throw 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)\n        adjMat[i][j] = 1;\n        adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    public void RemoveEdge(int i, int j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= Size() || j >= Size() || i == j)\n            throw new IndexOutOfRangeException();\n        adjMat[i][j] = 0;\n        adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    public void Print() {\n        Console.Write(\"\u9876\u70b9\u5217\u8868 = \");\n        PrintUtil.PrintList(vertices);\n        Console.WriteLine(\"\u90bb\u63a5\u77e9\u9635 =\");\n        PrintUtil.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\n    vertices []int\n    // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n    adjMat [][]int\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjMat(vertices []int, edges [][]int) *graphAdjMat {\n    // \u6dfb\u52a0\u9876\u70b9\n    n := len(vertices)\n    adjMat := make([][]int, n)\n    for i := range adjMat {\n        adjMat[i] = make([]int, n)\n    }\n    // \u521d\u59cb\u5316\u56fe\n    g := &graphAdjMat{\n        vertices: vertices,\n        adjMat:   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\n    for i := range edges {\n        g.addEdge(edges[i][0], edges[i][1])\n    }\n    return g\n}\n\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjMat) size() int {\n    return len(g.vertices)\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjMat) addVertex(val int) {\n    n := g.size()\n    // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n    g.vertices = append(g.vertices, val)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n    newRow := make([]int, n)\n    g.adjMat = append(g.adjMat, newRow)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n    for i := range g.adjMat {\n        g.adjMat[i] = append(g.adjMat[i], 0)\n    }\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjMat) removeVertex(index int) {\n    if index >= g.size() {\n        return\n    }\n    // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n    g.vertices = append(g.vertices[:index], g.vertices[index+1:]...)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n    g.adjMat = append(g.adjMat[:index], g.adjMat[index+1:]...)\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n    for i := range g.adjMat {\n        g.adjMat[i] = append(g.adjMat[i][:index], g.adjMat[i][index+1:]...)\n    }\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\n    if i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\n        fmt.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)\n    g.adjMat[i][j] = 1\n    g.adjMat[j][i] = 1\n}\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\n    if i < 0 || j < 0 || i >= g.size() || j >= g.size() || i == j {\n        fmt.Errorf(\"%s\", \"Index Out Of Bounds Exception\")\n    }\n    g.adjMat[i][j] = 0\n    g.adjMat[j][i] = 0\n}\n\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nfunc (g *graphAdjMat) print() {\n    fmt.Printf(\"\\t\u9876\u70b9\u5217\u8868 = %v\\n\", g.vertices)\n    fmt.Printf(\"\\t\u90bb\u63a5\u77e9\u9635 = \\n\")\n    for i := range g.adjMat {\n        fmt.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 {\n    private 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\n    private var adjMat: [[Int]] // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init(vertices: [Int], edges: [[Int]]) {\n        self.vertices = []\n        adjMat = []\n        // \u6dfb\u52a0\u9876\u70b9\n        for val in vertices {\n            addVertex(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\n        for e in edges {\n            addEdge(i: e[0], j: e[1])\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    func size() -> Int {\n        vertices.count\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    func addVertex(val: Int) {\n        let n = size()\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        vertices.append(val)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        let newRow = Array(repeating: 0, count: n)\n        adjMat.append(newRow)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for i in adjMat.indices {\n            adjMat[i].append(0)\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    func removeVertex(index: Int) {\n        if index >= size() {\n            fatalError(\"\u8d8a\u754c\")\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        vertices.remove(at: index)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        adjMat.remove(at: index)\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for i in adjMat.indices {\n            adjMat[i].remove(at: index)\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    func addEdge(i: Int, j: Int) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if i < 0 || j < 0 || i >= size() || j >= size() || i == j {\n            fatalError(\"\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)\n        adjMat[i][j] = 1\n        adjMat[j][i] = 1\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    func removeEdge(i: Int, j: Int) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if i < 0 || j < 0 || i >= size() || j >= size() || i == j {\n            fatalError(\"\u8d8a\u754c\")\n        }\n        adjMat[i][j] = 0\n        adjMat[j][i] = 0\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    func print() {\n        Swift.print(\"\u9876\u70b9\u5217\u8868 = \", terminator: \"\")\n        Swift.print(vertices)\n        Swift.print(\"\u90bb\u63a5\u77e9\u9635 =\")\n        PrintUtil.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 {\n    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\n    adjMat; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u51fd\u6570 */\n    constructor(vertices, edges) {\n        this.vertices = [];\n        this.adjMat = [];\n        // \u6dfb\u52a0\u9876\u70b9\n        for (const val of vertices) {\n            this.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\n        for (const e of edges) {\n            this.addEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size() {\n        return this.vertices.length;\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(val) {\n        const n = this.size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        this.vertices.push(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        const newRow = [];\n        for (let j = 0; j < n; j++) {\n            newRow.push(0);\n        }\n        this.adjMat.push(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (const row of this.adjMat) {\n            row.push(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(index) {\n        if (index >= this.size()) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        this.vertices.splice(index, 1);\n\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        this.adjMat.splice(index, 1);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (const row of this.adjMat) {\n            row.splice(index, 1);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    addEdge(i, j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw 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)\n        this.adjMat[i][j] = 1;\n        this.adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    removeEdge(i, j) {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        this.adjMat[i][j] = 0;\n        this.adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    print() {\n        console.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\n        console.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 {\n    vertices: 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\n    adjMat: number[][]; // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n    /* \u6784\u9020\u51fd\u6570 */\n    constructor(vertices: number[], edges: number[][]) {\n        this.vertices = [];\n        this.adjMat = [];\n        // \u6dfb\u52a0\u9876\u70b9\n        for (const val of vertices) {\n            this.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\n        for (const e of edges) {\n            this.addEdge(e[0], e[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size(): number {\n        return this.vertices.length;\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(val: number): void {\n        const n: number = this.size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        this.vertices.push(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        const newRow: number[] = [];\n        for (let j: number = 0; j < n; j++) {\n            newRow.push(0);\n        }\n        this.adjMat.push(newRow);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for (const row of this.adjMat) {\n            row.push(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(index: number): void {\n        if (index >= this.size()) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        this.vertices.splice(index, 1);\n\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        this.adjMat.splice(index, 1);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for (const row of this.adjMat) {\n            row.splice(index, 1);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    addEdge(i: number, j: number): void {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw 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)\n        this.adjMat[i][j] = 1;\n        this.adjMat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    removeEdge(i: number, j: number): void {\n        // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n        if (i < 0 || j < 0 || i >= this.size() || j >= this.size() || i === j) {\n            throw new RangeError('Index Out Of Bounds Exception');\n        }\n        this.adjMat[i][j] = 0;\n        this.adjMat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    print(): void {\n        console.log('\u9876\u70b9\u5217\u8868 = ', this.vertices);\n        console.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 {\n  List<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\n  List<List<int>> adjMat = []; //\u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  GraphAdjMat(List<int> vertices, List<List<int>> edges) {\n    this.vertices = [];\n    this.adjMat = [];\n    // \u6dfb\u52a0\u9876\u70b9\n    for (int val in vertices) {\n      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\n    for (List<int> e in edges) {\n      addEdge(e[0], e[1]);\n    }\n  }\n\n  /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n  int size() {\n    return vertices.length;\n  }\n\n  /* \u6dfb\u52a0\u9876\u70b9 */\n  void addVertex(int val) {\n    int n = size();\n    // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n    vertices.add(val);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n    List<int> newRow = List.filled(n, 0, growable: true);\n    adjMat.add(newRow);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n    for (List<int> row in adjMat) {\n      row.add(0);\n    }\n  }\n\n  /* \u5220\u9664\u9876\u70b9 */\n  void removeVertex(int index) {\n    if (index >= size()) {\n      throw IndexError;\n    }\n    // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n    vertices.removeAt(index);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n    adjMat.removeAt(index);\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n    for (List<int> row in adjMat) {\n      row.removeAt(index);\n    }\n  }\n\n  /* \u6dfb\u52a0\u8fb9 */\n  // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n  void addEdge(int i, int j) {\n    // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n    if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n      throw 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)\n    adjMat[i][j] = 1;\n    adjMat[j][i] = 1;\n  }\n\n  /* \u5220\u9664\u8fb9 */\n  // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n  void removeEdge(int i, int j) {\n    // \u7d22\u5f15\u8d8a\u754c\u4e0e\u76f8\u7b49\u5904\u7406\n    if (i < 0 || j < 0 || i >= size() || j >= size() || i == j) {\n      throw IndexError;\n    }\n    adjMat[i][j] = 0;\n    adjMat[j][i] = 0;\n  }\n\n  /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n  void printAdjMat() {\n    print(\"\u9876\u70b9\u5217\u8868 = $vertices\");\n    print(\"\u90bb\u63a5\u77e9\u9635 = \");\n    printMatrix(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\n    pub vertices: Vec<i32>,\n    // \u90bb\u63a5\u77e9\u9635\uff0c\u884c\u5217\u7d22\u5f15\u5bf9\u5e94\u201c\u9876\u70b9\u7d22\u5f15\u201d\n    pub adj_mat: Vec<Vec<i32>>,\n}\n\nimpl GraphAdjMat {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(vertices: Vec<i32>, edges: Vec<[usize; 2]>) -> Self {\n        let mut graph = GraphAdjMat {\n            vertices: vec![],\n            adj_mat: vec![],\n        };\n        // \u6dfb\u52a0\u9876\u70b9\n        for val in vertices {\n            graph.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\n        for edge in edges {\n            graph.add_edge(edge[0], edge[1])\n        }\n\n        graph\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    pub fn size(&self) -> usize {\n        self.vertices.len()\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    pub fn add_vertex(&mut self, val: i32) {\n        let n = self.size();\n        // \u5411\u9876\u70b9\u5217\u8868\u4e2d\u6dfb\u52a0\u65b0\u9876\u70b9\u7684\u503c\n        self.vertices.push(val);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u884c\n        self.adj_mat.push(vec![0; n]);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u6dfb\u52a0\u4e00\u5217\n        for row in &mut self.adj_mat {\n            row.push(0);\n        }\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    pub fn remove_vertex(&mut self, index: usize) {\n        if index >= self.size() {\n            panic!(\"index error\")\n        }\n        // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n        self.vertices.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n        self.adj_mat.remove(index);\n        // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n        for row in &mut self.adj_mat {\n            row.remove(index);\n        }\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    pub 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\n        if i >= self.size() || j >= self.size() || i == j {\n            panic!(\"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)\n        self.adj_mat[i][j] = 1;\n        self.adj_mat[j][i] = 1;\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    // \u53c2\u6570 i, j \u5bf9\u5e94 vertices \u5143\u7d20\u7d22\u5f15\n    pub 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\n        if i >= self.size() || j >= self.size() || i == j {\n            panic!(\"index error\")\n        }\n        self.adj_mat[i][j] = 0;\n        self.adj_mat[j][i] = 0;\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\n    pub fn print(&self) {\n        println!(\"\u9876\u70b9\u5217\u8868 = {:?}\", self.vertices);\n        println!(\"\u90bb\u63a5\u77e9\u9635 =\");\n        println!(\"[\");\n        for row in &self.adj_mat {\n            println!(\"  {:?},\", row);\n        }\n        println!(\"]\")\n    }\n}\n
    graph_adjacency_matrix.c
    /* \u57fa\u4e8e\u90bb\u63a5\u77e9\u9635\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7ed3\u6784\u4f53 */\ntypedef struct {\n    int vertices[MAX_SIZE];\n    int adjMat[MAX_SIZE][MAX_SIZE];\n    int size;\n} GraphAdjMat;\n\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjMat *newGraphAdjMat() {\n    GraphAdjMat *graph = (GraphAdjMat *)malloc(sizeof(GraphAdjMat));\n    graph->size = 0;\n    for (int i = 0; i < MAX_SIZE; i++) {\n        for (int j = 0; j < MAX_SIZE; j++) {\n            graph->adjMat[i][j] = 0;\n        }\n    }\n    return graph;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjMat(GraphAdjMat *graph) {\n    free(graph);\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjMat *graph, int val) {\n    if (graph->size == MAX_SIZE) {\n        fprintf(stderr, \"\u56fe\u7684\u9876\u70b9\u6570\u91cf\u5df2\u8fbe\u6700\u5927\u503c\\n\");\n        return;\n    }\n    // \u6dfb\u52a0\u7b2c n \u4e2a\u9876\u70b9\uff0c\u5e76\u5c06\u7b2c n \u884c\u548c\u5217\u7f6e\u96f6\n    int n = graph->size;\n    graph->vertices[n] = val;\n    for (int i = 0; i <= n; i++) {\n        graph->adjMat[n][i] = graph->adjMat[i][n] = 0;\n    }\n    graph->size++;\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjMat *graph, int index) {\n    if (index < 0 || index >= graph->size) {\n        fprintf(stderr, \"\u9876\u70b9\u7d22\u5f15\u8d8a\u754c\\n\");\n        return;\n    }\n    // \u5728\u9876\u70b9\u5217\u8868\u4e2d\u79fb\u9664\u7d22\u5f15 index \u7684\u9876\u70b9\n    for (int i = index; i < graph->size - 1; i++) {\n        graph->vertices[i] = graph->vertices[i + 1];\n    }\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u884c\n    for (int i = index; i < graph->size - 1; i++) {\n        for (int j = 0; j < graph->size; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i + 1][j];\n        }\n    }\n    // \u5728\u90bb\u63a5\u77e9\u9635\u4e2d\u5220\u9664\u7d22\u5f15 index \u7684\u5217\n    for (int i = 0; i < graph->size; i++) {\n        for (int j = index; j < graph->size - 1; j++) {\n            graph->adjMat[i][j] = graph->adjMat[i][j + 1];\n        }\n    }\n    graph->size--;\n}\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) {\n    if (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\n        fprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\n        return;\n    }\n    graph->adjMat[i][j] = 1;\n    graph->adjMat[j][i] = 1;\n}\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) {\n    if (i < 0 || j < 0 || i >= graph->size || j >= graph->size || i == j) {\n        fprintf(stderr, \"\u8fb9\u7d22\u5f15\u8d8a\u754c\u6216\u76f8\u7b49\\n\");\n        return;\n    }\n    graph->adjMat[i][j] = 0;\n    graph->adjMat[j][i] = 0;\n}\n\n/* \u6253\u5370\u90bb\u63a5\u77e9\u9635 */\nvoid printGraphAdjMat(GraphAdjMat *graph) {\n    printf(\"\u9876\u70b9\u5217\u8868 = \");\n    printArray(graph->vertices, graph->size);\n    printf(\"\u90bb\u63a5\u77e9\u9635 =\\n\");\n    for (int i = 0; i < graph->size; i++) {\n        printArray(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\"\"\"\n\n    def __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\n        self.adj_list = dict[Vertex, list[Vertex]]()\n        # \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for edge in edges:\n            self.add_vertex(edge[0])\n            self.add_vertex(edge[1])\n            self.add_edge(edge[0], edge[1])\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u9876\u70b9\u6570\u91cf\"\"\"\n        return len(self.adj_list)\n\n    def add_edge(self, vet1: Vertex, vet2: Vertex):\n        \"\"\"\u6dfb\u52a0\u8fb9\"\"\"\n        if vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\n            raise ValueError()\n        # \u6dfb\u52a0\u8fb9 vet1 - vet2\n        self.adj_list[vet1].append(vet2)\n        self.adj_list[vet2].append(vet1)\n\n    def remove_edge(self, vet1: Vertex, vet2: Vertex):\n        \"\"\"\u5220\u9664\u8fb9\"\"\"\n        if vet1 not in self.adj_list or vet2 not in self.adj_list or vet1 == vet2:\n            raise ValueError()\n        # \u5220\u9664\u8fb9 vet1 - vet2\n        self.adj_list[vet1].remove(vet2)\n        self.adj_list[vet2].remove(vet1)\n\n    def add_vertex(self, vet: Vertex):\n        \"\"\"\u6dfb\u52a0\u9876\u70b9\"\"\"\n        if vet in self.adj_list:\n            return\n        # \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        self.adj_list[vet] = []\n\n    def remove_vertex(self, vet: Vertex):\n        \"\"\"\u5220\u9664\u9876\u70b9\"\"\"\n        if vet not in self.adj_list:\n            raise ValueError()\n        # \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        self.adj_list.pop(vet)\n        # \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for vertex in self.adj_list:\n            if vet in self.adj_list[vertex]:\n                self.adj_list[vertex].remove(vet)\n\n    def print(self):\n        \"\"\"\u6253\u5370\u90bb\u63a5\u8868\"\"\"\n        print(\"\u90bb\u63a5\u8868 =\")\n        for vertex in self.adj_list:\n            tmp = [v.val for v in self.adj_list[vertex]]\n            print(f\"{vertex.val}: {tmp},\")\n
    graph_adjacency_list.cpp
    /* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\nclass GraphAdjList {\n  public:\n    // \u90bb\u63a5\u8868\uff0ckey\uff1a\u9876\u70b9\uff0cvalue\uff1a\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    unordered_map<Vertex *, vector<Vertex *>> adjList;\n\n    /* \u5728 vector \u4e2d\u5220\u9664\u6307\u5b9a\u8282\u70b9 */\n    void remove(vector<Vertex *> &vec, Vertex *vet) {\n        for (int i = 0; i < vec.size(); i++) {\n            if (vec[i] == vet) {\n                vec.erase(vec.begin() + i);\n                break;\n            }\n        }\n    }\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    GraphAdjList(const vector<vector<Vertex *>> &edges) {\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (const vector<Vertex *> &edge : edges) {\n            addVertex(edge[0]);\n            addVertex(edge[1]);\n            addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int size() {\n        return adjList.size();\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    void addEdge(Vertex *vet1, Vertex *vet2) {\n        if (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\n            throw invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList[vet1].push_back(vet2);\n        adjList[vet2].push_back(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    void removeEdge(Vertex *vet1, Vertex *vet2) {\n        if (!adjList.count(vet1) || !adjList.count(vet2) || vet1 == vet2)\n            throw invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        remove(adjList[vet1], vet2);\n        remove(adjList[vet2], vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    void addVertex(Vertex *vet) {\n        if (adjList.count(vet))\n            return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList[vet] = vector<Vertex *>();\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    void removeVertex(Vertex *vet) {\n        if (!adjList.count(vet))\n            throw invalid_argument(\"\u4e0d\u5b58\u5728\u9876\u70b9\");\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.erase(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (auto &adj : adjList) {\n            remove(adj.second, vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    void print() {\n        cout << \"\u90bb\u63a5\u8868 =\" << endl;\n        for (auto &adj : adjList) {\n            const auto &key = adj.first;\n            const auto &vec = adj.second;\n            cout << key->val << \": \";\n            printVector(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\n    Map<Vertex, List<Vertex>> adjList;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public GraphAdjList(Vertex[][] edges) {\n        this.adjList = new HashMap<>();\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (Vertex[] edge : edges) {\n            addVertex(edge[0]);\n            addVertex(edge[1]);\n            addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    public int size() {\n        return adjList.size();\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    public void addEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\n            throw new IllegalArgumentException();\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList.get(vet1).add(vet2);\n        adjList.get(vet2).add(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    public void removeEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.containsKey(vet1) || !adjList.containsKey(vet2) || vet1 == vet2)\n            throw new IllegalArgumentException();\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        adjList.get(vet1).remove(vet2);\n        adjList.get(vet2).remove(vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void addVertex(Vertex vet) {\n        if (adjList.containsKey(vet))\n            return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList.put(vet, new ArrayList<>());\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void removeVertex(Vertex vet) {\n        if (!adjList.containsKey(vet))\n            throw new IllegalArgumentException();\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.remove(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (List<Vertex> list : adjList.values()) {\n            list.remove(vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    public void print() {\n        System.out.println(\"\u90bb\u63a5\u8868 =\");\n        for (Map.Entry<Vertex, List<Vertex>> pair : adjList.entrySet()) {\n            List<Integer> tmp = new ArrayList<>();\n            for (Vertex vertex : pair.getValue())\n                tmp.add(vertex.val);\n            System.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\n    public Dictionary<Vertex, List<Vertex>> adjList;\n\n    /* \u6784\u9020\u51fd\u6570 */\n    public GraphAdjList(Vertex[][] edges) {\n        adjList = [];\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        foreach (Vertex[] edge in edges) {\n            AddVertex(edge[0]);\n            AddVertex(edge[1]);\n            AddEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    int Size() {\n        return adjList.Count;\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    public void AddEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\n            throw new InvalidOperationException();\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList[vet1].Add(vet2);\n        adjList[vet2].Add(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    public void RemoveEdge(Vertex vet1, Vertex vet2) {\n        if (!adjList.ContainsKey(vet1) || !adjList.ContainsKey(vet2) || vet1 == vet2)\n            throw new InvalidOperationException();\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        adjList[vet1].Remove(vet2);\n        adjList[vet2].Remove(vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public void AddVertex(Vertex vet) {\n        if (adjList.ContainsKey(vet))\n            return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList.Add(vet, []);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public void RemoveVertex(Vertex vet) {\n        if (!adjList.ContainsKey(vet))\n            throw new InvalidOperationException();\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.Remove(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        foreach (List<Vertex> list in adjList.Values) {\n            list.Remove(vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    public void Print() {\n        Console.WriteLine(\"\u90bb\u63a5\u8868 =\");\n        foreach (KeyValuePair<Vertex, List<Vertex>> pair in adjList) {\n            List<int> tmp = [];\n            foreach (Vertex vertex in pair.Value)\n                tmp.Add(vertex.val);\n            Console.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\n    adjList map[Vertex][]Vertex\n}\n\n/* \u6784\u9020\u51fd\u6570 */\nfunc newGraphAdjList(edges [][]Vertex) *graphAdjList {\n    g := &graphAdjList{\n        adjList: make(map[Vertex][]Vertex),\n    }\n    // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n    for _, edge := range edges {\n        g.addVertex(edge[0])\n        g.addVertex(edge[1])\n        g.addEdge(edge[0], edge[1])\n    }\n    return g\n}\n\n/* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\nfunc (g *graphAdjList) size() int {\n    return len(g.adjList)\n}\n\n/* \u6dfb\u52a0\u8fb9 */\nfunc (g *graphAdjList) addEdge(vet1 Vertex, vet2 Vertex) {\n    _, ok1 := g.adjList[vet1]\n    _, ok2 := g.adjList[vet2]\n    if !ok1 || !ok2 || vet1 == vet2 {\n        panic(\"error\")\n    }\n    // \u6dfb\u52a0\u8fb9 vet1 - vet2, \u6dfb\u52a0\u533f\u540d struct{},\n    g.adjList[vet1] = append(g.adjList[vet1], vet2)\n    g.adjList[vet2] = append(g.adjList[vet2], vet1)\n}\n\n/* \u5220\u9664\u8fb9 */\nfunc (g *graphAdjList) removeEdge(vet1 Vertex, vet2 Vertex) {\n    _, ok1 := g.adjList[vet1]\n    _, ok2 := g.adjList[vet2]\n    if !ok1 || !ok2 || vet1 == vet2 {\n        panic(\"error\")\n    }\n    // \u5220\u9664\u8fb9 vet1 - vet2\n    g.adjList[vet1] = DeleteSliceElms(g.adjList[vet1], vet2)\n    g.adjList[vet2] = DeleteSliceElms(g.adjList[vet2], vet1)\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nfunc (g *graphAdjList) addVertex(vet Vertex) {\n    _, ok := g.adjList[vet]\n    if ok {\n        return\n    }\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n    g.adjList[vet] = make([]Vertex, 0)\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nfunc (g *graphAdjList) removeVertex(vet Vertex) {\n    _, ok := g.adjList[vet]\n    if !ok {\n        panic(\"error\")\n    }\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n    delete(g.adjList, vet)\n    // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n    for v, list := range g.adjList {\n        g.adjList[v] = DeleteSliceElms(list, vet)\n    }\n}\n\n/* \u6253\u5370\u90bb\u63a5\u8868 */\nfunc (g *graphAdjList) print() {\n    var builder strings.Builder\n    fmt.Printf(\"\u90bb\u63a5\u8868 = \\n\")\n    for k, v := range g.adjList {\n        builder.WriteString(\"\\t\\t\" + strconv.Itoa(k.Val) + \": \")\n        for _, vet := range v {\n            builder.WriteString(strconv.Itoa(vet.Val) + \" \")\n        }\n        fmt.Println(builder.String())\n        builder.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\n    public private(set) var adjList: [Vertex: [Vertex]]\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public init(edges: [[Vertex]]) {\n        adjList = [:]\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for edge in edges {\n            addVertex(vet: edge[0])\n            addVertex(vet: edge[1])\n            addEdge(vet1: edge[0], vet2: edge[1])\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    public func size() -> Int {\n        adjList.count\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    public func addEdge(vet1: Vertex, vet2: Vertex) {\n        if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\n            fatalError(\"\u53c2\u6570\u9519\u8bef\")\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        adjList[vet1]?.append(vet2)\n        adjList[vet2]?.append(vet1)\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    public func removeEdge(vet1: Vertex, vet2: Vertex) {\n        if adjList[vet1] == nil || adjList[vet2] == nil || vet1 == vet2 {\n            fatalError(\"\u53c2\u6570\u9519\u8bef\")\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        adjList[vet1]?.removeAll(where: { $0 == vet2 })\n        adjList[vet2]?.removeAll(where: { $0 == vet1 })\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    public func addVertex(vet: Vertex) {\n        if adjList[vet] != nil {\n            return\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        adjList[vet] = []\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    public func removeVertex(vet: Vertex) {\n        if adjList[vet] == nil {\n            fatalError(\"\u53c2\u6570\u9519\u8bef\")\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        adjList.removeValue(forKey: vet)\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for key in adjList.keys {\n            adjList[key]?.removeAll(where: { $0 == vet })\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    public func print() {\n        Swift.print(\"\u90bb\u63a5\u8868 =\")\n        for pair in adjList {\n            var tmp: [Int] = []\n            for vertex in pair.value {\n                tmp.append(vertex.val)\n            }\n            Swift.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\n    adjList;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(edges) {\n        this.adjList = new Map();\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (const edge of edges) {\n            this.addVertex(edge[0]);\n            this.addVertex(edge[1]);\n            this.addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size() {\n        return this.adjList.size;\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    addEdge(vet1, vet2) {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).push(vet2);\n        this.adjList.get(vet2).push(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    removeEdge(vet1, vet2) {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\n        this.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(vet) {\n        if (this.adjList.has(vet)) return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        this.adjList.set(vet, []);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(vet) {\n        if (!this.adjList.has(vet)) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        this.adjList.delete(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (const set of this.adjList.values()) {\n            const index = set.indexOf(vet);\n            if (index > -1) {\n                set.splice(index, 1);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    print() {\n        console.log('\u90bb\u63a5\u8868 =');\n        for (const [key, value] of this.adjList) {\n            const tmp = [];\n            for (const vertex of value) {\n                tmp.push(vertex.val);\n            }\n            console.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\n    adjList: Map<Vertex, Vertex[]>;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(edges: Vertex[][]) {\n        this.adjList = new Map();\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for (const edge of edges) {\n            this.addVertex(edge[0]);\n            this.addVertex(edge[1]);\n            this.addEdge(edge[0], edge[1]);\n        }\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    size(): number {\n        return this.adjList.size;\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    addEdge(vet1: Vertex, vet2: Vertex): void {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).push(vet2);\n        this.adjList.get(vet2).push(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    removeEdge(vet1: Vertex, vet2: Vertex): void {\n        if (\n            !this.adjList.has(vet1) ||\n            !this.adjList.has(vet2) ||\n            vet1 === vet2\n        ) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        this.adjList.get(vet1).splice(this.adjList.get(vet1).indexOf(vet2), 1);\n        this.adjList.get(vet2).splice(this.adjList.get(vet2).indexOf(vet1), 1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    addVertex(vet: Vertex): void {\n        if (this.adjList.has(vet)) return;\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        this.adjList.set(vet, []);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    removeVertex(vet: Vertex): void {\n        if (!this.adjList.has(vet)) {\n            throw new Error('Illegal Argument Exception');\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        this.adjList.delete(vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for (const set of this.adjList.values()) {\n            const index: number = set.indexOf(vet);\n            if (index > -1) {\n                set.splice(index, 1);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    print(): void {\n        console.log('\u90bb\u63a5\u8868 =');\n        for (const [key, value] of this.adjList.entries()) {\n            const tmp = [];\n            for (const vertex of value) {\n                tmp.push(vertex.val);\n            }\n            console.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\n  Map<Vertex, List<Vertex>> adjList = {};\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  GraphAdjList(List<List<Vertex>> edges) {\n    for (List<Vertex> edge in edges) {\n      addVertex(edge[0]);\n      addVertex(edge[1]);\n      addEdge(edge[0], edge[1]);\n    }\n  }\n\n  /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n  int size() {\n    return adjList.length;\n  }\n\n  /* \u6dfb\u52a0\u8fb9 */\n  void addEdge(Vertex vet1, Vertex vet2) {\n    if (!adjList.containsKey(vet1) ||\n        !adjList.containsKey(vet2) ||\n        vet1 == vet2) {\n      throw ArgumentError;\n    }\n    // \u6dfb\u52a0\u8fb9 vet1 - vet2\n    adjList[vet1]!.add(vet2);\n    adjList[vet2]!.add(vet1);\n  }\n\n  /* \u5220\u9664\u8fb9 */\n  void removeEdge(Vertex vet1, Vertex vet2) {\n    if (!adjList.containsKey(vet1) ||\n        !adjList.containsKey(vet2) ||\n        vet1 == vet2) {\n      throw ArgumentError;\n    }\n    // \u5220\u9664\u8fb9 vet1 - vet2\n    adjList[vet1]!.remove(vet2);\n    adjList[vet2]!.remove(vet1);\n  }\n\n  /* \u6dfb\u52a0\u9876\u70b9 */\n  void addVertex(Vertex vet) {\n    if (adjList.containsKey(vet)) return;\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n    adjList[vet] = [];\n  }\n\n  /* \u5220\u9664\u9876\u70b9 */\n  void removeVertex(Vertex vet) {\n    if (!adjList.containsKey(vet)) {\n      throw ArgumentError;\n    }\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n    adjList.remove(vet);\n    // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n    adjList.forEach((key, value) {\n      value.remove(vet);\n    });\n  }\n\n  /* \u6253\u5370\u90bb\u63a5\u8868 */\n  void printAdjList() {\n    print(\"\u90bb\u63a5\u8868 =\");\n    adjList.forEach((key, value) {\n      List<int> tmp = [];\n      for (Vertex vertex in value) {\n        tmp.add(vertex.val);\n      }\n      print(\"${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\n    pub adj_list: HashMap<Vertex, Vec<Vertex>>,\n}\n\nimpl GraphAdjList {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(edges: Vec<[Vertex; 2]>) -> Self {\n        let mut graph = GraphAdjList {\n            adj_list: HashMap::new(),\n        };\n        // \u6dfb\u52a0\u6240\u6709\u9876\u70b9\u548c\u8fb9\n        for edge in edges {\n            graph.add_vertex(edge[0]);\n            graph.add_vertex(edge[1]);\n            graph.add_edge(edge[0], edge[1]);\n        }\n\n        graph\n    }\n\n    /* \u83b7\u53d6\u9876\u70b9\u6570\u91cf */\n    #[allow(unused)]\n    pub fn size(&self) -> usize {\n        self.adj_list.len()\n    }\n\n    /* \u6dfb\u52a0\u8fb9 */\n    pub fn add_edge(&mut self, vet1: Vertex, vet2: Vertex) {\n        if !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n        {\n            panic!(\"value error\");\n        }\n        // \u6dfb\u52a0\u8fb9 vet1 - vet2\n        self.adj_list.get_mut(&vet1).unwrap().push(vet2);\n        self.adj_list.get_mut(&vet2).unwrap().push(vet1);\n    }\n\n    /* \u5220\u9664\u8fb9 */\n    #[allow(unused)]\n    pub fn remove_edge(&mut self, vet1: Vertex, vet2: Vertex) {\n        if !self.adj_list.contains_key(&vet1) || !self.adj_list.contains_key(&vet2) || vet1 == vet2\n        {\n            panic!(\"value error\");\n        }\n        // \u5220\u9664\u8fb9 vet1 - vet2\n        self.adj_list\n            .get_mut(&vet1)\n            .unwrap()\n            .retain(|&vet| vet != vet2);\n        self.adj_list\n            .get_mut(&vet2)\n            .unwrap()\n            .retain(|&vet| vet != vet1);\n    }\n\n    /* \u6dfb\u52a0\u9876\u70b9 */\n    pub fn add_vertex(&mut self, vet: Vertex) {\n        if self.adj_list.contains_key(&vet) {\n            return;\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n        self.adj_list.insert(vet, vec![]);\n    }\n\n    /* \u5220\u9664\u9876\u70b9 */\n    #[allow(unused)]\n    pub fn remove_vertex(&mut self, vet: Vertex) {\n        if !self.adj_list.contains_key(&vet) {\n            panic!(\"value error\");\n        }\n        // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n        self.adj_list.remove(&vet);\n        // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n        for list in self.adj_list.values_mut() {\n            list.retain(|&v| v != vet);\n        }\n    }\n\n    /* \u6253\u5370\u90bb\u63a5\u8868 */\n    pub fn print(&self) {\n        println!(\"\u90bb\u63a5\u8868 =\");\n        for (vertex, list) in &self.adj_list {\n            let list = list.iter().map(|vertex| vertex.val).collect::<Vec<i32>>();\n            println!(\"{}: {:?},\", vertex.val, list);\n        }\n    }\n}\n
    graph_adjacency_list.c
    /* \u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct AdjListNode {\n    Vertex *vertex;           // \u9876\u70b9\n    struct AdjListNode *next; // \u540e\u7ee7\u8282\u70b9\n} AdjListNode;\n\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\n    for (int i = 0; i < graph->size; i++) {\n        if (graph->heads[i]->vertex == vet) {\n            return graph->heads[i];\n        }\n    }\n    return NULL;\n}\n\n/* \u6dfb\u52a0\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid addEdgeHelper(AdjListNode *head, Vertex *vet) {\n    AdjListNode *node = (AdjListNode *)malloc(sizeof(AdjListNode));\n    node->vertex = vet;\n    // \u5934\u63d2\u6cd5\n    node->next = head->next;\n    head->next = node;\n}\n\n/* \u5220\u9664\u8fb9\u8f85\u52a9\u51fd\u6570 */\nvoid removeEdgeHelper(AdjListNode *head, Vertex *vet) {\n    AdjListNode *pre = head;\n    AdjListNode *cur = head->next;\n    // \u5728\u94fe\u8868\u4e2d\u641c\u7d22 vet \u5bf9\u5e94\u8282\u70b9\n    while (cur != NULL && cur->vertex != vet) {\n        pre = cur;\n        cur = cur->next;\n    }\n    if (cur == NULL)\n        return;\n    // \u5c06 vet \u5bf9\u5e94\u8282\u70b9\u4ece\u94fe\u8868\u4e2d\u5220\u9664\n    pre->next = cur->next;\n    // \u91ca\u653e\u5185\u5b58\n    free(cur);\n}\n\n/* \u57fa\u4e8e\u90bb\u63a5\u8868\u5b9e\u73b0\u7684\u65e0\u5411\u56fe\u7c7b */\ntypedef struct {\n    AdjListNode *heads[MAX_SIZE]; // \u8282\u70b9\u6570\u7ec4\n    int size;                     // \u8282\u70b9\u6570\u91cf\n} GraphAdjList;\n\n/* \u6784\u9020\u51fd\u6570 */\nGraphAdjList *newGraphAdjList() {\n    GraphAdjList *graph = (GraphAdjList *)malloc(sizeof(GraphAdjList));\n    if (!graph) {\n        return NULL;\n    }\n    graph->size = 0;\n    for (int i = 0; i < MAX_SIZE; i++) {\n        graph->heads[i] = NULL;\n    }\n    return graph;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delGraphAdjList(GraphAdjList *graph) {\n    for (int i = 0; i < graph->size; i++) {\n        AdjListNode *cur = graph->heads[i];\n        while (cur != NULL) {\n            AdjListNode *next = cur->next;\n            if (cur != graph->heads[i]) {\n                free(cur);\n            }\n            cur = next;\n        }\n        free(graph->heads[i]->vertex);\n        free(graph->heads[i]);\n    }\n    free(graph);\n}\n\n/* \u67e5\u627e\u9876\u70b9\u5bf9\u5e94\u7684\u8282\u70b9 */\nAdjListNode *findNode(GraphAdjList *graph, Vertex *vet) {\n    for (int i = 0; i < graph->size; i++) {\n        if (graph->heads[i]->vertex == vet) {\n            return graph->heads[i];\n        }\n    }\n    return NULL;\n}\n\n/* \u6dfb\u52a0\u8fb9 */\nvoid addEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\n    AdjListNode *head1 = findNode(graph, vet1);\n    AdjListNode *head2 = findNode(graph, vet2);\n    assert(head1 != NULL && head2 != NULL && head1 != head2);\n    // \u6dfb\u52a0\u8fb9 vet1 - vet2\n    addEdgeHelper(head1, vet2);\n    addEdgeHelper(head2, vet1);\n}\n\n/* \u5220\u9664\u8fb9 */\nvoid removeEdge(GraphAdjList *graph, Vertex *vet1, Vertex *vet2) {\n    AdjListNode *head1 = findNode(graph, vet1);\n    AdjListNode *head2 = findNode(graph, vet2);\n    assert(head1 != NULL && head2 != NULL);\n    // \u5220\u9664\u8fb9 vet1 - vet2\n    removeEdgeHelper(head1, head2->vertex);\n    removeEdgeHelper(head2, head1->vertex);\n}\n\n/* \u6dfb\u52a0\u9876\u70b9 */\nvoid addVertex(GraphAdjList *graph, Vertex *vet) {\n    assert(graph != NULL && graph->size < MAX_SIZE);\n    AdjListNode *head = (AdjListNode *)malloc(sizeof(AdjListNode));\n    head->vertex = vet;\n    head->next = NULL;\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u94fe\u8868\n    graph->heads[graph->size++] = head;\n}\n\n/* \u5220\u9664\u9876\u70b9 */\nvoid removeVertex(GraphAdjList *graph, Vertex *vet) {\n    AdjListNode *node = findNode(graph, vet);\n    assert(node != NULL);\n    // \u5728\u90bb\u63a5\u8868\u4e2d\u5220\u9664\u9876\u70b9 vet \u5bf9\u5e94\u7684\u94fe\u8868\n    AdjListNode *cur = node, *pre = NULL;\n    while (cur) {\n        pre = cur;\n        cur = cur->next;\n        free(pre);\n    }\n    // \u904d\u5386\u5176\u4ed6\u9876\u70b9\u7684\u94fe\u8868\uff0c\u5220\u9664\u6240\u6709\u5305\u542b vet \u7684\u8fb9\n    for (int i = 0; i < graph->size; i++) {\n        cur = graph->heads[i];\n        pre = NULL;\n        while (cur) {\n            pre = cur;\n            cur = cur->next;\n            if (cur && cur->vertex == vet) {\n                pre->next = cur->next;\n                free(cur);\n                break;\n            }\n        }\n    }\n    // \u5c06\u8be5\u9876\u70b9\u4e4b\u540e\u7684\u9876\u70b9\u5411\u524d\u79fb\u52a8\uff0c\u4ee5\u586b\u8865\u7a7a\u7f3a\n    int i;\n    for (i = 0; i < graph->size; i++) {\n        if (graph->heads[i] == node)\n            break;\n    }\n    for (int j = i; j < graph->size - 1; j++) {\n        graph->heads[j] = graph->heads[j + 1];\n    }\n    graph->size--;\n    free(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\u4e5f\u53ef\u5206\u4e3a\u4e24\u79cd\uff1a\u300c\u5e7f\u5ea6\u4f18\u5148\u904d\u5386\u300d\u548c\u300c\u6df1\u5ea6\u4f18\u5148\u904d\u5386\u300d\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\"\"\"\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\n    res = []\n    # \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited = set[Vertex]([start_vet])\n    # \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    que = deque[Vertex]([start_vet])\n    # \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while len(que) > 0:\n        vet = que.popleft()  # \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        # \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for adj_vet in graph.adj_list[vet]:\n            if adj_vet in visited:\n                continue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            que.append(adj_vet)  # \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.add(adj_vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    # \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n
    graph_bfs.cpp
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    vector<Vertex *> res;\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    unordered_set<Vertex *> visited = {startVet};\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    queue<Vertex *> que;\n    que.push(startVet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (!que.empty()) {\n        Vertex *vet = que.front();\n        que.pop();          // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push_back(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (auto adjVet : graph.adjList[vet]) {\n            if (visited.count(adjVet))\n                continue;            // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            que.push(adjVet);        // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.emplace(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.java
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = new ArrayList<>();\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    Set<Vertex> visited = new HashSet<>();\n    visited.add(startVet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    Queue<Vertex> que = new LinkedList<>();\n    que.offer(startVet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (!que.isEmpty()) {\n        Vertex vet = que.poll(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.add(vet);            // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (Vertex adjVet : graph.adjList.get(vet)) {\n            if (visited.contains(adjVet))\n                continue;        // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            que.offer(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.cs
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    HashSet<Vertex> visited = [startVet];\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    Queue<Vertex> que = new();\n    que.Enqueue(startVet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (que.Count > 0) {\n        Vertex vet = que.Dequeue(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.Add(vet);               // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        foreach (Vertex adjVet in graph.adjList[vet]) {\n            if (visited.Contains(adjVet)) {\n                continue;          // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.Enqueue(adjVet);   // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.Add(adjVet);   // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.go
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    res := make([]Vertex, 0)\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited := make(map[Vertex]struct{})\n    visited[startVet] = struct{}{}\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS, \u4f7f\u7528\u5207\u7247\u6a21\u62df\u961f\u5217\n    queue := make([]Vertex, 0)\n    queue = append(queue, startVet)\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    for len(queue) > 0 {\n        // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        vet := queue[0]\n        queue = queue[1:]\n        // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        res = append(res, vet)\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for _, adjVet := range g.adjList[vet] {\n            _, isExist := visited[adjVet]\n            // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            if !isExist {\n                queue = append(queue, adjVet)\n                visited[adjVet] = struct{}{}\n            }\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n}\n
    graph_bfs.swift
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    var res: [Vertex] = []\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    var visited: Set<Vertex> = [startVet]\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    var que: [Vertex] = [startVet]\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while !que.isEmpty {\n        let vet = que.removeFirst() // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for adjVet in graph.adjList[vet] ?? [] {\n            if visited.contains(adjVet) {\n                continue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.append(adjVet) // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.insert(adjVet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n}\n
    graph_bfs.js
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited = new Set();\n    visited.add(startVet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    const que = [startVet];\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (que.length) {\n        const vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (const adjVet of graph.adjList.get(vet) ?? []) {\n            if (visited.has(adjVet)) {\n                continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n            visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.ts
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res: Vertex[] = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited: Set<Vertex> = new Set();\n    visited.add(startVet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    const que = [startVet];\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (que.length) {\n        const vet = que.shift(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        for (const adjVet of graph.adjList.get(vet) ?? []) {\n            if (visited.has(adjVet)) {\n                continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            que.push(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\n            visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res;\n}\n
    graph_bfs.dart
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n  List<Vertex> res = [];\n  // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n  Set<Vertex> visited = {};\n  visited.add(startVet);\n  // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n  Queue<Vertex> que = Queue();\n  que.add(startVet);\n  // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n  while (que.isNotEmpty) {\n    Vertex vet = que.removeFirst(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n    res.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (Vertex adjVet in graph.adjList[vet]!) {\n      if (visited.contains(adjVet)) {\n        continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n      }\n      que.add(adjVet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n      visited.add(adjVet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    }\n  }\n  // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n  return res;\n}\n
    graph_bfs.rs
    /* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    let mut res = vec![];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    let mut visited = HashSet::new();\n    visited.insert(start_vet);\n    // \u961f\u5217\u7528\u4e8e\u5b9e\u73b0 BFS\n    let mut que = VecDeque::new();\n    que.push_back(start_vet);\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while !que.is_empty() {\n        let vet = que.pop_front().unwrap(); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n                    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        if let Some(adj_vets) = graph.adj_list.get(&vet) {\n            for &adj_vet in adj_vets {\n                if visited.contains(&adj_vet) {\n                    continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n                }\n                que.push_back(adj_vet); // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n                visited.insert(adj_vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n            }\n        }\n    }\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    res\n}\n
    graph_bfs.c
    /* \u8282\u70b9\u961f\u5217\u7ed3\u6784\u4f53 */\ntypedef struct {\n    Vertex *vertices[MAX_SIZE];\n    int front, rear, size;\n} Queue;\n\n/* \u6784\u9020\u51fd\u6570 */\nQueue *newQueue() {\n    Queue *q = (Queue *)malloc(sizeof(Queue));\n    q->front = q->rear = q->size = 0;\n    return q;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nint isEmpty(Queue *q) {\n    return q->size == 0;\n}\n\n/* \u5165\u961f\u64cd\u4f5c */\nvoid enqueue(Queue *q, Vertex *vet) {\n    q->vertices[q->rear] = vet;\n    q->rear = (q->rear + 1) % MAX_SIZE;\n    q->size++;\n}\n\n/* \u51fa\u961f\u64cd\u4f5c */\nVertex *dequeue(Queue *q) {\n    Vertex *vet = q->vertices[q->front];\n    q->front = (q->front + 1) % MAX_SIZE;\n    q->size--;\n    return vet;\n}\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\n    for (int i = 0; i < size; i++) {\n        if (visited[i] == vet)\n            return 1;\n    }\n    return 0;\n}\n\n/* \u5e7f\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    Queue *queue = newQueue();\n    enqueue(queue, startVet);\n    visited[(*visitedSize)++] = startVet;\n    // \u4ee5\u9876\u70b9 vet \u4e3a\u8d77\u70b9\uff0c\u5faa\u73af\u76f4\u81f3\u8bbf\u95ee\u5b8c\u6240\u6709\u9876\u70b9\n    while (!isEmpty(queue)) {\n        Vertex *vet = dequeue(queue); // \u961f\u9996\u9876\u70b9\u51fa\u961f\n        res[(*resSize)++] = vet;      // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n        // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n        AdjListNode *node = findNode(graph, vet);\n        while (node != NULL) {\n            // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            if (!isVisited(visited, *visitedSize, node->vertex)) {\n                enqueue(queue, node->vertex);             // \u53ea\u5165\u961f\u672a\u8bbf\u95ee\u7684\u9876\u70b9\n                visited[(*visitedSize)++] = node->vertex; // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n            }\n            node = node->next;\n        }\n    }\n    // \u91ca\u653e\u5185\u5b58\n    free(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\u8f85\u52a9\u51fd\u6570\"\"\"\n    res.append(vet)  # \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet)  # \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    # \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for adjVet in graph.adj_list[vet]:\n        if adjVet in visited:\n            continue  # \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        # \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet)\n\ndef graph_dfs(graph: GraphAdjList, start_vet: Vertex) -> list[Vertex]:\n    \"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386\"\"\"\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\n    res = []\n    # \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited = set[Vertex]()\n    dfs(graph, visited, res, start_vet)\n    return res\n
    graph_dfs.cpp
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList &graph, unordered_set<Vertex *> &visited, vector<Vertex *> &res, Vertex *vet) {\n    res.push_back(vet);   // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.emplace(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (Vertex *adjVet : graph.adjList[vet]) {\n        if (visited.count(adjVet))\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    vector<Vertex *> res;\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    unordered_set<Vertex *> visited;\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.java
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList graph, Set<Vertex> visited, List<Vertex> res, Vertex vet) {\n    res.add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (Vertex adjVet : graph.adjList.get(vet)) {\n        if (visited.contains(adjVet))\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = new ArrayList<>();\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    Set<Vertex> visited = new HashSet<>();\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.cs
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid DFS(GraphAdjList graph, HashSet<Vertex> visited, List<Vertex> res, Vertex vet) {\n    res.Add(vet);     // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.Add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    foreach (Vertex adjVet in graph.adjList[vet]) {\n        if (visited.Contains(adjVet)) {\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9                             \n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        DFS(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    List<Vertex> res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    HashSet<Vertex> visited = [];\n    DFS(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.go
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\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)\n    visited[vet] = struct{}{}\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for _, adjVet := range g.adjList[vet] {\n        _, isExist := visited[adjVet]\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        if !isExist {\n            dfs(g, visited, res, adjVet)\n        }\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    res := make([]Vertex, 0)\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    visited := make(map[Vertex]struct{})\n    dfs(g, visited, &res, startVet)\n    // \u8fd4\u56de\u9876\u70b9\u904d\u5386\u5e8f\u5217\n    return res\n}\n
    graph_dfs.swift
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nfunc dfs(graph: GraphAdjList, visited: inout Set<Vertex>, res: inout [Vertex], vet: Vertex) {\n    res.append(vet) // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.insert(vet) // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for adjVet in graph.adjList[vet] ?? [] {\n        if visited.contains(adjVet) {\n            continue // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph: graph, visited: &visited, res: &res, vet: adjVet)\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    var res: [Vertex] = []\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    var visited: Set<Vertex> = []\n    dfs(graph: graph, visited: &visited, res: &res, vet: startVet)\n    return res\n}\n
    graph_dfs.js
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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) {\n    res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (const adjVet of graph.adjList.get(vet)) {\n        if (visited.has(adjVet)) {\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited = new Set();\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.ts
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nfunction dfs(\n    graph: GraphAdjList,\n    visited: Set<Vertex>,\n    res: Vertex[],\n    vet: Vertex\n): void {\n    res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    for (const adjVet of graph.adjList.get(vet)) {\n        if (visited.has(adjVet)) {\n            continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        }\n        // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n        dfs(graph, visited, res, adjVet);\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    const res: Vertex[] = [];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    const visited: Set<Vertex> = new Set();\n    dfs(graph, visited, res, startVet);\n    return res;\n}\n
    graph_dfs.dart
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(\n  GraphAdjList graph,\n  Set<Vertex> visited,\n  List<Vertex> res,\n  Vertex vet,\n) {\n  res.add(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n  visited.add(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n  // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n  for (Vertex adjVet in graph.adjList[vet]!) {\n    if (visited.contains(adjVet)) {\n      continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n    }\n    // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n    dfs(graph, visited, res, adjVet);\n  }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\nList<Vertex> graphDFS(GraphAdjList graph, Vertex startVet) {\n  // \u9876\u70b9\u904d\u5386\u5e8f\u5217\n  List<Vertex> res = [];\n  // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n  Set<Vertex> visited = {};\n  dfs(graph, visited, res, startVet);\n  return res;\n}\n
    graph_dfs.rs
    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nfn dfs(graph: &GraphAdjList, visited: &mut HashSet<Vertex>, res: &mut Vec<Vertex>, vet: Vertex) {\n    res.push(vet); // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    visited.insert(vet); // \u6807\u8bb0\u8be5\u9876\u70b9\u5df2\u88ab\u8bbf\u95ee\n                         // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    if let Some(adj_vets) = graph.adj_list.get(&vet) {\n        for &adj_vet in adj_vets {\n            if visited.contains(&adj_vet) {\n                continue; // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n            }\n            // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n            dfs(graph, visited, res, adj_vet);\n        }\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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\n    let mut res = vec![];\n    // \u54c8\u5e0c\u8868\uff0c\u7528\u4e8e\u8bb0\u5f55\u5df2\u88ab\u8bbf\u95ee\u8fc7\u7684\u9876\u70b9\n    let mut visited = HashSet::new();\n    dfs(&graph, &mut visited, &mut res, start_vet);\n\n    res\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\n    for (int i = 0; i < size; i++) {\n        if (res[i] == vet) {\n            return 1;\n        }\n    }\n    return 0;\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386\u8f85\u52a9\u51fd\u6570 */\nvoid dfs(GraphAdjList *graph, Vertex **res, int *resSize, Vertex *vet) {\n    // \u8bb0\u5f55\u8bbf\u95ee\u9876\u70b9\n    res[(*resSize)++] = vet;\n    // \u904d\u5386\u8be5\u9876\u70b9\u7684\u6240\u6709\u90bb\u63a5\u9876\u70b9\n    AdjListNode *node = findNode(graph, vet);\n    while (node != NULL) {\n        // \u8df3\u8fc7\u5df2\u88ab\u8bbf\u95ee\u7684\u9876\u70b9\n        if (!isVisited(res, *resSize, node->vertex)) {\n            // \u9012\u5f52\u8bbf\u95ee\u90bb\u63a5\u9876\u70b9\n            dfs(graph, res, resSize, node->vertex);\n        }\n        node = node->next;\n    }\n}\n\n/* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\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) {\n    dfs(graph, res, resSize, startVet);\n}\n
    graph_dfs.zig
    [class]{}-[func]{dfs}\n\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\"\"\"\n\n    def __init__(self, w: int, v: int):\n        self.w = w  # \u7269\u54c1\u91cd\u91cf\n        self.v = v  # \u7269\u54c1\u4ef7\u503c\n\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\n    items = [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\n    items.sort(key=lambda item: item.v / item.w, reverse=True)\n    # \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    res = 0\n    for item in items:\n        if item.w <= cap:\n            # \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v\n            cap -= 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\n            res += (item.v / item.w) * cap\n            # \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break\n    return res\n
    fractional_knapsack.cpp
    /* \u7269\u54c1 */\nclass Item {\n  public:\n    int w; // \u7269\u54c1\u91cd\u91cf\n    int v; // \u7269\u54c1\u4ef7\u503c\n\n    Item(int w, int v) : w(w), v(v) {\n    }\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\n    vector<Item> items;\n    for (int i = 0; i < wgt.size(); i++) {\n        items.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\n    sort(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\n    double res = 0;\n    for (auto &item : items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (double)item.v / item.w * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.java
    /* \u7269\u54c1 */\nclass Item {\n    int w; // \u7269\u54c1\u91cd\u91cf\n    int v; // \u7269\u54c1\u4ef7\u503c\n\n    public Item(int w, int v) {\n        this.w = w;\n        this.v = v;\n    }\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\n    Item[] items = new Item[wgt.length];\n    for (int i = 0; i < wgt.length; i++) {\n        items[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\n    Arrays.sort(items, Comparator.comparingDouble(item -> -((double) item.v / item.w)));\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    double res = 0;\n    for (Item item : items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (double) item.v / item.w * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.cs
    /* \u7269\u54c1 */\nclass Item(int w, int v) {\n    public int w = w; // \u7269\u54c1\u91cd\u91cf\n    public int v = v; // \u7269\u54c1\u4ef7\u503c\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\n    Item[] items = new Item[wgt.Length];\n    for (int i = 0; i < wgt.Length; i++) {\n        items[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\n    Array.Sort(items, (x, y) => (y.v / y.w).CompareTo(x.v / x.w));\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    double res = 0;\n    foreach (Item item in items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (double)item.v / item.w * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.go
    /* \u7269\u54c1 */\ntype Item struct {\n    w int // \u7269\u54c1\u91cd\u91cf\n    v int // \u7269\u54c1\u4ef7\u503c\n}\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\n    items := make([]Item, len(wgt))\n    for i := 0; i < len(wgt); i++ {\n        items[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\n    sort.Slice(items, func(i, j int) bool {\n        return float64(items[i].v)/float64(items[i].w) > float64(items[j].v)/float64(items[j].w)\n    })\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    res := 0.0\n    for _, item := range items {\n        if item.w <= cap {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += float64(item.v)\n            cap -= 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\n            res += float64(item.v) / float64(item.w) * float64(cap)\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break\n        }\n    }\n    return res\n}\n
    fractional_knapsack.swift
    /* \u7269\u54c1 */\nclass Item {\n    var w: Int // \u7269\u54c1\u91cd\u91cf\n    var v: Int // \u7269\u54c1\u4ef7\u503c\n\n    init(w: Int, v: Int) {\n        self.w = w\n        self.v = v\n    }\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\n    var 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\n    items.sort(by: { -(Double($0.v) / Double($0.w)) < -(Double($1.v) / Double($1.w)) })\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    var res = 0.0\n    var cap = cap\n    for item in items {\n        if item.w <= cap {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += Double(item.v)\n            cap -= 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\n            res += Double(item.v) / Double(item.w) * Double(cap)\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break\n        }\n    }\n    return res\n}\n
    fractional_knapsack.js
    /* \u7269\u54c1 */\nclass Item {\n    constructor(w, v) {\n        this.w = w; // \u7269\u54c1\u91cd\u91cf\n        this.v = v; // \u7269\u54c1\u4ef7\u503c\n    }\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\n    const 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\n    items.sort((a, b) => b.v / b.w - a.v / a.w);\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    let res = 0;\n    for (const item of items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (item.v / item.w) * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.ts
    /* \u7269\u54c1 */\nclass Item {\n    w: number; // \u7269\u54c1\u91cd\u91cf\n    v: number; // \u7269\u54c1\u4ef7\u503c\n\n    constructor(w: number, v: number) {\n        this.w = w;\n        this.v = v;\n    }\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\n    const 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\n    items.sort((a, b) => b.v / b.w - a.v / a.w);\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    let res = 0;\n    for (const item of items) {\n        if (item.w <= cap) {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v;\n            cap -= 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\n            res += (item.v / item.w) * cap;\n            // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    return res;\n}\n
    fractional_knapsack.dart
    /* \u7269\u54c1 */\nclass Item {\n  int w; // \u7269\u54c1\u91cd\u91cf\n  int v; // \u7269\u54c1\u4ef7\u503c\n\n  Item(this.w, this.v);\n}\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\n  List<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\n  items.sort((a, b) => (b.v / b.w).compareTo(a.v / a.w));\n  // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n  double res = 0;\n  for (Item item in items) {\n    if (item.w <= cap) {\n      // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n      res += item.v;\n      cap -= 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\n      res += item.v / item.w * cap;\n      // \u5df2\u65e0\u5269\u4f59\u5bb9\u91cf\uff0c\u56e0\u6b64\u8df3\u51fa\u5faa\u73af\n      break;\n    }\n  }\n  return res;\n}\n
    fractional_knapsack.rs
    /* \u7269\u54c1 */\nstruct Item {\n    w: i32, // \u7269\u54c1\u91cd\u91cf\n    v: i32, // \u7269\u54c1\u4ef7\u503c\n}\n\nimpl Item {\n    fn new(w: i32, v: i32) -> Self {\n        Self { w, v }\n    }\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\n    let 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\n    items.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\n    let mut res = 0.0;\n    for item in &items {\n        if item.w <= cap {\n            // \u82e5\u5269\u4f59\u5bb9\u91cf\u5145\u8db3\uff0c\u5219\u5c06\u5f53\u524d\u7269\u54c1\u6574\u4e2a\u88c5\u8fdb\u80cc\u5305\n            res += item.v as f64;\n            cap -= 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\n            res += 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\n            break;\n        }\n    }\n    res\n}\n
    fractional_knapsack.c
    /* \u7269\u54c1 */\ntypedef struct {\n    int w; // \u7269\u54c1\u91cd\u91cf\n    int v; // \u7269\u54c1\u4ef7\u503c\n} Item;\n\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\n    Item *items = malloc(sizeof(Item) * itemCount);\n    for (int i = 0; i < itemCount; i++) {\n        items[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\n    qsort(items, (size_t)itemCount, sizeof(Item), sortByValueDensity);\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\n    float res = 0.0;\n    for (int i = 0; i < itemCount; i++) {\n        if (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\n            res += items[i].v;\n            cap -= 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\n            res += (float)cap / items[i].w * items[i].v;\n            cap = 0;\n            break;\n        }\n    }\n    free(items);\n    return res;\n}\n
    fractional_knapsack.zig
    [class]{Item}-[func]{}\n\n[class]{}-[func]{fractionalKnapsack}\n

    \u9664\u6392\u5e8f\u4e4b\u5916\uff0c\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\u56f4\u6210\u7684\u6700\u5927\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\uff0c\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\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\n    i = len(coins) - 1\n    count = 0\n    # \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while amt > 0:\n        # \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while i > 0 and coins[i] > amt:\n            i -= 1\n        # \u9009\u62e9 coins[i]\n        amt -= coins[i]\n        count += 1\n    # \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    int i = coins.size() - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    int i = coins.length - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    int i = coins.Length - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    i := len(coins) - 1\n    count := 0\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    for amt > 0 {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        for i > 0 && coins[i] > amt {\n            i--\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i]\n        count++\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    if amt != 0 {\n        return -1\n    }\n    return 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\n    var i = coins.count - 1\n    var count = 0\n    var amt = amt\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while amt > 0 {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while i > 0 && coins[i] > amt {\n            i -= 1\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i]\n        count += 1\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    let i = coins.length - 1;\n    let count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n    let i = coins.length - 1;\n    let count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return 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\n  int i = coins.length - 1;\n  int count = 0;\n  // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n  while (amt > 0) {\n    // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n    while (i > 0 && coins[i] > amt) {\n      i--;\n    }\n    // \u9009\u62e9 coins[i]\n    amt -= coins[i];\n    count++;\n  }\n  // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n  return 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\n    let mut i = coins.len() - 1;\n    let mut count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while amt > 0 {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while i > 0 && coins[i] > amt {\n            i -= 1;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count += 1;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    if amt == 0 {\n        count\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\n    int i = size - 1;\n    int count = 0;\n    // \u5faa\u73af\u8fdb\u884c\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u5230\u65e0\u5269\u4f59\u91d1\u989d\n    while (amt > 0) {\n        // \u627e\u5230\u5c0f\u4e8e\u4e14\u6700\u63a5\u8fd1\u5269\u4f59\u91d1\u989d\u7684\u786c\u5e01\n        while (i > 0 && coins[i] > amt) {\n            i--;\n        }\n        // \u9009\u62e9 coins[i]\n        amt -= coins[i];\n        count++;\n    }\n    // \u82e5\u672a\u627e\u5230\u53ef\u884c\u65b9\u6848\uff0c\u5219\u8fd4\u56de -1\n    return amt == 0 ? count : -1;\n}\n
    coin_change_greedy.zig
    [class]{}-[func]{coinChangeGreedy}\n

    \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\u3002

    "},{"location":"chapter_greedy/greedy_algorithm/#1511","title":"15.1.1 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5\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)\\) \u964d\u4f4e\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\u7b97\u6cd5\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, D. A polynomial-time algorithm for the change-making problem[J]. Operations Research Letters, 2005, 33(3): 231-234.

    "},{"location":"chapter_greedy/greedy_algorithm/#1513","title":"15.1.3 \u00a0 \u8d2a\u5fc3\u7b97\u6cd5\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\u7b97\u6cd5\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\uff0c\u4f7f\u5176\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\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\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    i, j = 0, len(ht) - 1\n    # \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    res = 0\n    # \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while i < j:\n        # \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        cap = min(ht[i], ht[j]) * (j - i)\n        res = max(res, cap)\n        # \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j]:\n            i += 1\n        else:\n            j -= 1\n    return res\n
    max_capacity.cpp
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(vector<int> &ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0, j = ht.size() - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int cap = min(ht[i], ht[j]) * (j - i);\n        res = max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return res;\n}\n
    max_capacity.java
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int[] ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0, j = ht.length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int cap = Math.min(ht[i], ht[j]) * (j - i);\n        res = Math.max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return res;\n}\n
    max_capacity.cs
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint MaxCapacity(int[] ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0, j = ht.Length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int cap = Math.Min(ht[i], ht[j]) * (j - i);\n        res = Math.Max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return res;\n}\n
    max_capacity.go
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht []int) int {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    i, j := 0, len(ht)-1\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    res := 0\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    for i < j {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        capacity := int(math.Min(float64(ht[i]), float64(ht[j]))) * (j - i)\n        res = int(math.Max(float64(res), float64(capacity)))\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j] {\n            i++\n        } else {\n            j--\n        }\n    }\n    return res\n}\n
    max_capacity.swift
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunc maxCapacity(ht: [Int]) -> Int {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    var i = 0, j = ht.count - 1\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    var res = 0\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while i < j {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        let cap = min(ht[i], ht[j]) * (j - i)\n        res = max(res, cap)\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j] {\n            i += 1\n        } else {\n            j -= 1\n        }\n    }\n    return res\n}\n
    max_capacity.js
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    let i = 0,\n        j = ht.length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    let res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        const cap = Math.min(ht[i], ht[j]) * (j - i);\n        res = Math.max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i += 1;\n        } else {\n            j -= 1;\n        }\n    }\n    return res;\n}\n
    max_capacity.ts
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nfunction maxCapacity(ht: number[]): number {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    let i = 0,\n        j = ht.length - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    let res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        const cap: number = Math.min(ht[i], ht[j]) * (j - i);\n        res = Math.max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i += 1;\n        } else {\n            j -= 1;\n        }\n    }\n    return res;\n}\n
    max_capacity.dart
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(List<int> ht) {\n  // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n  int i = 0, j = ht.length - 1;\n  // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n  int res = 0;\n  // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n  while (i < j) {\n    // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n    int cap = min(ht[i], ht[j]) * (j - i);\n    res = max(res, cap);\n    // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n    if (ht[i] < ht[j]) {\n      i++;\n    } else {\n      j--;\n    }\n  }\n  return 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\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    let mut i = 0;\n    let mut j = ht.len() - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    let mut res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while i < j {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        let cap = std::cmp::min(ht[i], ht[j]) * (j - i) as i32;\n        res = std::cmp::max(res, cap);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if ht[i] < ht[j] {\n            i += 1;\n        } else {\n            j -= 1;\n        }\n    }\n    res\n}\n
    max_capacity.c
    /* \u6700\u5927\u5bb9\u91cf\uff1a\u8d2a\u5fc3 */\nint maxCapacity(int ht[], int htLength) {\n    // \u521d\u59cb\u5316 i, j\uff0c\u4f7f\u5176\u5206\u5217\u6570\u7ec4\u4e24\u7aef\n    int i = 0;\n    int j = htLength - 1;\n    // \u521d\u59cb\u6700\u5927\u5bb9\u91cf\u4e3a 0\n    int res = 0;\n    // \u5faa\u73af\u8d2a\u5fc3\u9009\u62e9\uff0c\u76f4\u81f3\u4e24\u677f\u76f8\u9047\n    while (i < j) {\n        // \u66f4\u65b0\u6700\u5927\u5bb9\u91cf\n        int capacity = myMin(ht[i], ht[j]) * (j - i);\n        res = myMax(res, capacity);\n        // \u5411\u5185\u79fb\u52a8\u77ed\u677f\n        if (ht[i] < ht[j]) {\n            i++;\n        } else {\n            j--;\n        }\n    }\n    return 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\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\n    if n <= 3:\n        return 1 * (n - 1)\n    # \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    a, b = n // 3, n % 3\n    if b == 1:\n        # \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return int(math.pow(3, a - 1)) * 2 * 2\n    if b == 2:\n        # \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return int(math.pow(3, a)) * 2\n    # \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return (int)pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return (int)pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return (int) Math.pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return (int) Math.pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return (int)Math.Pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return (int)Math.Pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (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\n    if n <= 3 {\n        return 1 * (n - 1)\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    a := n / 3\n    b := n % 3\n    if b == 1 {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return int(math.Pow(3, float64(a-1))) * 2 * 2\n    }\n    if b == 2 {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return int(math.Pow(3, float64(a))) * 2\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if n <= 3 {\n        return 1 * (n - 1)\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a = n / 3\n    let b = n % 3\n    if b == 1 {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return pow(3, a - 1) * 2 * 2\n    }\n    if b == 2 {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return pow(3, a) * 2\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a = Math.floor(n / 3);\n    let b = n % 3;\n    if (b === 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return Math.pow(3, a - 1) * 2 * 2;\n    }\n    if (b === 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return Math.pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a: number = Math.floor(n / 3);\n    let b: number = n % 3;\n    if (b === 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return Math.pow(3, a - 1) * 2 * 2;\n    }\n    if (b === 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return Math.pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\n  if (n <= 3) {\n    return 1 * (n - 1);\n  }\n  // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n  int a = n ~/ 3;\n  int b = n % 3;\n  if (b == 1) {\n    // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n    return (pow(3, a - 1) * 2 * 2).toInt();\n  }\n  if (b == 2) {\n    // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return (pow(3, a) * 2).toInt();\n  }\n  // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n  return 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\n    if n <= 3 {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    let a = n / 3;\n    let b = n % 3;\n    if b == 1 {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        3_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\n        3_i32.pow(a as u32) * 2\n    } else {\n        // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        3_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\n    if (n <= 3) {\n        return 1 * (n - 1);\n    }\n    // \u8d2a\u5fc3\u5730\u5207\u5206\u51fa 3 \uff0ca \u4e3a 3 \u7684\u4e2a\u6570\uff0cb \u4e3a\u4f59\u6570\n    int a = n / 3;\n    int b = n % 3;\n    if (b == 1) {\n        // \u5f53\u4f59\u6570\u4e3a 1 \u65f6\uff0c\u5c06\u4e00\u5bf9 1 * 3 \u8f6c\u5316\u4e3a 2 * 2\n        return pow(3, a - 1) * 2 * 2;\n    }\n    if (b == 2) {\n        // \u5f53\u4f59\u6570\u4e3a 2 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n        return pow(3, a) * 2;\n    }\n    // \u5f53\u4f59\u6570\u4e3a 0 \u65f6\uff0c\u4e0d\u505a\u5904\u7406\n    return 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\uff0c\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\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash += ord(c)\n    return hash % modulus\n\ndef mul_hash(key: str) -> int:\n    \"\"\"\u4e58\u6cd5\u54c8\u5e0c\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash = 31 * hash + ord(c)\n    return hash % modulus\n\ndef xor_hash(key: str) -> int:\n    \"\"\"\u5f02\u6216\u54c8\u5e0c\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash ^= ord(c)\n    return hash % modulus\n\ndef rot_hash(key: str) -> int:\n    \"\"\"\u65cb\u8f6c\u54c8\u5e0c\"\"\"\n    hash = 0\n    modulus = 1000000007\n    for c in key:\n        hash = (hash << 4) ^ (hash >> 28) ^ ord(c)\n    return hash % modulus\n
    simple_hash.cpp
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(string key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash = (hash + (int)c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(string key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash = (31 * hash + (int)c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(string key) {\n    int hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash ^= (int)c;\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(string key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (unsigned char c : key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ (int)c) % MODULUS;\n    }\n    return (int)hash;\n}\n
    simple_hash.java
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\n    long hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash = (hash + (int) c) % MODULUS;\n    }\n    return (int) hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\n    long hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash = (31 * hash + (int) c) % MODULUS;\n    }\n    return (int) hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\n    int hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash ^= (int) c;\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\n    long hash = 0;\n    final int MODULUS = 1000000007;\n    for (char c : key.toCharArray()) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ (int) c) % MODULUS;\n    }\n    return (int) hash;\n}\n
    simple_hash.cs
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint AddHash(string key) {\n    long hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash = (hash + c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint MulHash(string key) {\n    long hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash = (31 * hash + c) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint XorHash(string key) {\n    int hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash ^= c;\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint RotHash(string key) {\n    long hash = 0;\n    const int MODULUS = 1000000007;\n    foreach (char c in key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c) % MODULUS;\n    }\n    return (int)hash;\n}\n
    simple_hash.go
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key string) int {\n    var hash int64\n    var modulus int64\n\n    modulus = 1000000007\n    for _, b := range []byte(key) {\n        hash = (hash + int64(b)) % modulus\n    }\n    return int(hash)\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key string) int {\n    var hash int64\n    var modulus int64\n\n    modulus = 1000000007\n    for _, b := range []byte(key) {\n        hash = (31*hash + int64(b)) % modulus\n    }\n    return int(hash)\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key string) int {\n    hash := 0\n    modulus := 1000000007\n    for _, b := range []byte(key) {\n        fmt.Println(int(b))\n        hash ^= int(b)\n        hash = (31*hash + int(b)) % modulus\n    }\n    return hash & modulus\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key string) int {\n    var hash int64\n    var modulus int64\n\n    modulus = 1000000007\n    for _, b := range []byte(key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ int64(b)) % modulus\n    }\n    return int(hash)\n}\n
    simple_hash.swift
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunc addHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash = (hash + Int(scalar.value)) % MODULUS\n        }\n    }\n    return hash\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunc mulHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash = (31 * hash + Int(scalar.value)) % MODULUS\n        }\n    }\n    return hash\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunc xorHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash ^= Int(scalar.value)\n        }\n    }\n    return hash & MODULUS\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunc rotHash(key: String) -> Int {\n    var hash = 0\n    let MODULUS = 1_000_000_007\n    for c in key {\n        for scalar in c.unicodeScalars {\n            hash = ((hash << 4) ^ (hash >> 28) ^ Int(scalar.value)) % MODULUS\n        }\n    }\n    return hash\n}\n
    simple_hash.js
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash ^= c.charCodeAt(0);\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key) {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n
    simple_hash.ts
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfunction addHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfunction mulHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = (31 * hash + c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfunction xorHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash ^= c.charCodeAt(0);\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfunction rotHash(key: string): number {\n    let hash = 0;\n    const MODULUS = 1000000007;\n    for (const c of key) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c.charCodeAt(0)) % MODULUS;\n    }\n    return hash;\n}\n
    simple_hash.dart
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash = (hash + key.codeUnitAt(i)) % MODULUS;\n  }\n  return hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash = (31 * hash + key.codeUnitAt(i)) % MODULUS;\n  }\n  return hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash ^= key.codeUnitAt(i);\n  }\n  return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(String key) {\n  int hash = 0;\n  final int MODULUS = 1000000007;\n  for (int i = 0; i < key.length; i++) {\n    hash = ((hash << 4) ^ (hash >> 28) ^ key.codeUnitAt(i)) % MODULUS;\n  }\n  return hash;\n}\n
    simple_hash.rs
    /* \u52a0\u6cd5\u54c8\u5e0c */\nfn add_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash = (hash + c as i64) % MODULUS;\n    }\n\n    hash as i32\n} \n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nfn mul_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash = (31 * hash + c as i64) % MODULUS;\n    }\n\n    hash as i32\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nfn xor_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash ^= c as i64;\n    }\n\n    (hash & MODULUS) as i32\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nfn rot_hash(key: &str) -> i32 {\n    let mut hash = 0_i64;\n    const MODULUS: i64 = 1000000007;\n\n    for c in key.chars() {\n        hash = ((hash << 4) ^ (hash >> 28) ^ c as i64) % MODULUS;\n    }\n\n    hash as i32\n}\n
    simple_hash.c
    /* \u52a0\u6cd5\u54c8\u5e0c */\nint addHash(char *key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (int i = 0; i < strlen(key); i++) {\n        hash = (hash + (unsigned char)key[i]) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u4e58\u6cd5\u54c8\u5e0c */\nint mulHash(char *key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (int i = 0; i < strlen(key); i++) {\n        hash = (31 * hash + (unsigned char)key[i]) % MODULUS;\n    }\n    return (int)hash;\n}\n\n/* \u5f02\u6216\u54c8\u5e0c */\nint xorHash(char *key) {\n    int hash = 0;\n    const int MODULUS = 1000000007;\n\n    for (int i = 0; i < strlen(key); i++) {\n        hash ^= (unsigned char)key[i];\n    }\n    return hash & MODULUS;\n}\n\n/* \u65cb\u8f6c\u54c8\u5e0c */\nint rotHash(char *key) {\n    long long hash = 0;\n    const int MODULUS = 1000000007;\n    for (int i = 0; i < strlen(key); i++) {\n        hash = ((hash << 4) ^ (hash >> 28) ^ (unsigned char)key[i]) % MODULUS;\n    }\n\n    return (int)hash;\n}\n
    simple_hash.zig
    [class]{}-[func]{addHash}\n\n[class]{}-[func]{mulHash}\n\n[class]{}-[func]{xorHash}\n\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 \u548c SHA-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 bit 160 bit 256/512 bit 224/256/384/512 bit \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\n\nbol = True\nhash_bol = hash(bol)\n# \u5e03\u5c14\u91cf True \u7684\u54c8\u5e0c\u503c\u4e3a 1\n\ndec = 3.14159\nhash_dec = hash(dec)\n# \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 326484311674566659\n\nstr = \"Hello \u7b97\u6cd5\"\nhash_str = hash(str)\n# \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 4617003410720528961\n\ntup = (12836, \"\u5c0f\u54c8\")\nhash_tup = hash(tup)\n# \u5143\u7ec4 (12836, '\u5c0f\u54c8') \u7684\u54c8\u5e0c\u503c\u4e3a 1029005403108185979\n\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\n\nbool bol = true;\nsize_t hashBol = hash<bool>()(bol);\n// \u5e03\u5c14\u91cf 1 \u7684\u54c8\u5e0c\u503c\u4e3a 1\n\ndouble dec = 3.14159;\nsize_t hashDec = hash<double>()(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 4614256650576692846\n\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\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\n\nboolean bol = true;\nint hashBol = Boolean.hashCode(bol);\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\n\ndouble dec = 3.14159;\nint hashDec = Double.hashCode(dec);\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729\n\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -727081396\n\nObject[] arr = { 12836, \"\u5c0f\u54c8\" };\nint hashTup = Arrays.hashCode(arr);\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 1151158\n\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;\n\nbool bol = true;\nint hashBol = bol.GetHashCode();\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a 1;\n\ndouble dec = 3.14159;\nint hashDec = dec.GetHashCode();\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -1340954729;\n\nstring str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.GetHashCode();\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -586107568;\n\nobject[] arr = [12836, \"\u5c0f\u54c8\"];\nint hashTup = arr.GetHashCode();\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 42931033;\n\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\n\nlet bol = true\nlet hashBol = bol.hashValue\n// \u5e03\u5c14\u91cf true \u7684\u54c8\u5e0c\u503c\u4e3a -4431640247352757451\n\nlet dec = 3.14159\nlet hashDec = dec.hashValue\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a -2465384235396674631\n\nlet str = \"Hello \u7b97\u6cd5\"\nlet hashStr = str.hashValue\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a -7850626797806988787\n\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\n\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\n\nbool bol = true;\nint hashBol = bol.hashCode;\n// \u5e03\u5c14\u503c true \u7684\u54c8\u5e0c\u503c\u4e3a 1231\n\ndouble dec = 3.14159;\nint hashDec = dec.hashCode;\n// \u5c0f\u6570 3.14159 \u7684\u54c8\u5e0c\u503c\u4e3a 2570631074981783\n\nString str = \"Hello \u7b97\u6cd5\";\nint hashStr = str.hashCode;\n// \u5b57\u7b26\u4e32\u201cHello \u7b97\u6cd5\u201d\u7684\u54c8\u5e0c\u503c\u4e3a 468167534\n\nList arr = [12836, \"\u5c0f\u54c8\"];\nint hashArr = arr.hashCode;\n// \u6570\u7ec4 [12836, \u5c0f\u54c8] \u7684\u54c8\u5e0c\u503c\u4e3a 976512528\n\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};\n\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\n\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\n\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\n\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\n\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\n\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\u4e86\u89e3\u51b3\u8be5\u95ee\u9898\uff0c\u6bcf\u5f53\u9047\u5230\u54c8\u5e0c\u51b2\u7a81\u65f6\uff0c\u6211\u4eec\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\uff1a\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\uff1a\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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\n        self.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\n        self.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        self.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\n        self.buckets = [[] for _ in range(self.capacity)]  # \u6876\u6570\u7ec4\n\n    def hash_func(self, key: int) -> int:\n        \"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\n        return key % self.capacity\n\n    def load_factor(self) -> float:\n        \"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\n        return self.size / self.capacity\n\n    def get(self, key: int) -> str | None:\n        \"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n        index = self.hash_func(key)\n        bucket = self.buckets[index]\n        # \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for pair in bucket:\n            if pair.key == key:\n                return pair.val\n        # \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de None\n        return None\n\n    def 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\n        if self.load_factor() > self.load_thres:\n            self.extend()\n        index = self.hash_func(key)\n        bucket = self.buckets[index]\n        # \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for pair in bucket:\n            if pair.key == key:\n                pair.val = val\n                return\n        # \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        pair = Pair(key, val)\n        bucket.append(pair)\n        self.size += 1\n\n    def remove(self, key: int):\n        \"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n        index = self.hash_func(key)\n        bucket = self.buckets[index]\n        # \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for pair in bucket:\n            if pair.key == key:\n                bucket.remove(pair)\n                self.size -= 1\n                break\n\n    def extend(self):\n        \"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n        # \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        buckets = self.buckets\n        # \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio\n        self.buckets = [[] for _ in range(self.capacity)]\n        self.size = 0\n        # \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for bucket in buckets:\n            for pair in bucket:\n                self.put(pair.key, pair.val)\n\n    def print(self):\n        \"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\n        for bucket in self.buckets:\n            res = []\n            for pair in bucket:\n                res.append(str(pair.key) + \" -> \" + pair.val)\n            print(res)\n
    hash_map_chaining.cpp
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n  private:\n    int size;                       // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity;                   // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres;               // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio;                // \u6269\u5bb9\u500d\u6570\n    vector<vector<Pair *>> buckets; // \u6876\u6570\u7ec4\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3.0), extendRatio(2) {\n        buckets.resize(capacity);\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~HashMapChaining() {\n        for (auto &bucket : buckets) {\n            for (Pair *pair : bucket) {\n                // \u91ca\u653e\u5185\u5b58\n                delete pair;\n            }\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double loadFactor() {\n        return (double)size / (double)capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    string get(int key) {\n        int index = hashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (Pair *pair : buckets[index]) {\n            if (pair->key == key) {\n                return pair->val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n        return \"\";\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        int index = hashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for (Pair *pair : buckets[index]) {\n            if (pair->key == key) {\n                pair->val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        buckets[index].push_back(new Pair(key, val));\n        size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        int index = hashFunc(key);\n        auto &bucket = buckets[index];\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (int i = 0; i < bucket.size(); i++) {\n            if (bucket[i]->key == key) {\n                Pair *tmp = bucket[i];\n                bucket.erase(bucket.begin() + i); // \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n                delete tmp;                       // \u91ca\u653e\u5185\u5b58\n                size--;\n                return;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        vector<vector<Pair *>> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets.clear();\n        buckets.resize(capacity);\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (auto &bucket : bucketsTmp) {\n            for (Pair *pair : bucket) {\n                put(pair->key, pair->val);\n                // \u91ca\u653e\u5185\u5b58\n                delete pair;\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (auto &bucket : buckets) {\n            cout << \"[\";\n            for (Pair *pair : bucket) {\n                cout << pair->key << \" -> \" << pair->val << \", \";\n            }\n            cout << \"]\\n\";\n        }\n    }\n};\n
    hash_map_chaining.java
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n    int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio; // \u6269\u5bb9\u500d\u6570\n    List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapChaining() {\n        size = 0;\n        capacity = 4;\n        loadThres = 2.0 / 3.0;\n        extendRatio = 2;\n        buckets = new ArrayList<>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.add(new ArrayList<>());\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double loadFactor() {\n        return (double) size / capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    String get(int key) {\n        int index = hashFunc(key);\n        List<Pair> bucket = buckets.get(index);\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (Pair pair : bucket) {\n            if (pair.key == key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, String val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        int index = hashFunc(key);\n        List<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\n        for (Pair pair : bucket) {\n            if (pair.key == key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        Pair pair = new Pair(key, val);\n        bucket.add(pair);\n        size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        int index = hashFunc(key);\n        List<Pair> bucket = buckets.get(index);\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (Pair pair : bucket) {\n            if (pair.key == key) {\n                bucket.remove(pair);\n                size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        List<List<Pair>> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new ArrayList<>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.add(new ArrayList<>());\n        }\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (List<Pair> bucket : bucketsTmp) {\n            for (Pair pair : bucket) {\n                put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (List<Pair> bucket : buckets) {\n            List<String> res = new ArrayList<>();\n            for (Pair pair : bucket) {\n                res.add(pair.key + \" -> \" + pair.val);\n            }\n            System.out.println(res);\n        }\n    }\n}\n
    hash_map_chaining.cs
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n    int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio; // \u6269\u5bb9\u500d\u6570\n    List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapChaining() {\n        size = 0;\n        capacity = 4;\n        loadThres = 2.0 / 3.0;\n        extendRatio = 2;\n        buckets = new List<List<Pair>>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.Add([]);\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int HashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double LoadFactor() {\n        return (double)size / capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public string? Get(int key) {\n        int index = HashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        foreach (Pair pair in buckets[index]) {\n            if (pair.key == key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void Put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (LoadFactor() > loadThres) {\n            Extend();\n        }\n        int index = HashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        foreach (Pair pair in buckets[index]) {\n            if (pair.key == key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        buckets[index].Add(new Pair(key, val));\n        size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void Remove(int key) {\n        int index = HashFunc(key);\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        foreach (Pair pair in buckets[index].ToList()) {\n            if (pair.key == key) {\n                buckets[index].Remove(pair);\n                size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void Extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        List<List<Pair>> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new List<List<Pair>>(capacity);\n        for (int i = 0; i < capacity; i++) {\n            buckets.Add([]);\n        }\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        foreach (List<Pair> bucket in bucketsTmp) {\n            foreach (Pair pair in bucket) {\n                Put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void Print() {\n        foreach (List<Pair> bucket in buckets) {\n            List<string> res = [];\n            foreach (Pair pair in bucket) {\n                res.Add(pair.key + \" -> \" + pair.val);\n            }\n            foreach (string kv in res) {\n                Console.WriteLine(kv);\n            }\n        }\n    }\n}\n
    hash_map_chaining.go
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntype hashMapChaining struct {\n    size        int      // \u952e\u503c\u5bf9\u6570\u91cf\n    capacity    int      // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    loadThres   float64  // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    extendRatio int      // \u6269\u5bb9\u500d\u6570\n    buckets     [][]pair // \u6876\u6570\u7ec4\n}\n\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapChaining() *hashMapChaining {\n    buckets := make([][]pair, 4)\n    for i := 0; i < 4; i++ {\n        buckets[i] = make([]pair, 0)\n    }\n    return &hashMapChaining{\n        size:        0,\n        capacity:    4,\n        loadThres:   2.0 / 3.0,\n        extendRatio: 2,\n        buckets:     buckets,\n    }\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapChaining) hashFunc(key int) int {\n    return key % m.capacity\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapChaining) loadFactor() float64 {\n    return float64(m.size) / float64(m.capacity)\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapChaining) get(key int) string {\n    idx := m.hashFunc(key)\n    bucket := m.buckets[idx]\n    // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    for _, p := range bucket {\n        if p.key == key {\n            return p.val\n        }\n    }\n    // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n    return \"\"\n}\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\n    if m.loadFactor() > m.loadThres {\n        m.extend()\n    }\n    idx := m.hashFunc(key)\n    // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n    for i := range m.buckets[idx] {\n        if m.buckets[idx][i].key == key {\n            m.buckets[idx][i].val = val\n            return\n        }\n    }\n    // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n    p := pair{\n        key: key,\n        val: val,\n    }\n    m.buckets[idx] = append(m.buckets[idx], p)\n    m.size += 1\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapChaining) remove(key int) {\n    idx := m.hashFunc(key)\n    // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n    for i, p := range m.buckets[idx] {\n        if p.key == key {\n            // \u5207\u7247\u5220\u9664\n            m.buckets[idx] = append(m.buckets[idx][:i], m.buckets[idx][i+1:]...)\n            m.size -= 1\n            break\n        }\n    }\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    tmpBuckets := make([][]pair, len(m.buckets))\n    for i := 0; i < len(m.buckets); i++ {\n        tmpBuckets[i] = make([]pair, len(m.buckets[i]))\n        copy(tmpBuckets[i], m.buckets[i])\n    }\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    m.capacity *= m.extendRatio\n    m.buckets = make([][]pair, m.capacity)\n    for i := 0; i < m.capacity; i++ {\n        m.buckets[i] = make([]pair, 0)\n    }\n    m.size = 0\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for _, bucket := range tmpBuckets {\n        for _, p := range bucket {\n            m.put(p.key, p.val)\n        }\n    }\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapChaining) print() {\n    var builder strings.Builder\n\n    for _, bucket := range m.buckets {\n        builder.WriteString(\"[\")\n        for _, p := range bucket {\n            builder.WriteString(strconv.Itoa(p.key) + \" -> \" + p.val + \" \")\n        }\n        builder.WriteString(\"]\")\n        fmt.Println(builder.String())\n        builder.Reset()\n    }\n}\n
    hash_map_chaining.swift
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n    var size: Int // \u952e\u503c\u5bf9\u6570\u91cf\n    var capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    var loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    var extendRatio: Int // \u6269\u5bb9\u500d\u6570\n    var buckets: [[Pair]] // \u6876\u6570\u7ec4\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init() {\n        size = 0\n        capacity = 4\n        loadThres = 2.0 / 3.0\n        extendRatio = 2\n        buckets = Array(repeating: [], count: capacity)\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    func hashFunc(key: Int) -> Int {\n        key % capacity\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    func loadFactor() -> Double {\n        Double(size / capacity)\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    func get(key: Int) -> String? {\n        let index = hashFunc(key: key)\n        let bucket = buckets[index]\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for pair in bucket {\n            if pair.key == key {\n                return pair.val\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de nil\n        return nil\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    func put(key: Int, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if loadFactor() > loadThres {\n            extend()\n        }\n        let index = hashFunc(key: key)\n        let bucket = buckets[index]\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for pair in bucket {\n            if pair.key == key {\n                pair.val = val\n                return\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        let pair = Pair(key: key, val: val)\n        buckets[index].append(pair)\n        size += 1\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    func remove(key: Int) {\n        let index = hashFunc(key: key)\n        let bucket = buckets[index]\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (pairIndex, pair) in bucket.enumerated() {\n            if pair.key == key {\n                buckets[index].remove(at: pairIndex)\n            }\n        }\n        size -= 1\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    func extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let bucketsTmp = buckets\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio\n        buckets = Array(repeating: [], count: capacity)\n        size = 0\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for bucket in bucketsTmp {\n            for pair in bucket {\n                put(key: pair.key, val: pair.val)\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    func print() {\n        for bucket in buckets {\n            let res = bucket.map { \"\\($0.key) -> \\($0.val)\" }\n            Swift.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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#size = 0;\n        this.#capacity = 4;\n        this.#loadThres = 2.0 / 3.0;\n        this.#extendRatio = 2;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key) {\n        return key % this.#capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    #loadFactor() {\n        return this.#size / this.#capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key) {\n        const index = this.#hashFunc(key);\n        const bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key, val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.#loadFactor() > this.#loadThres) {\n            this.#extend();\n        }\n        const index = this.#hashFunc(key);\n        const 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\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        const pair = new Pair(key, val);\n        bucket.push(pair);\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key) {\n        const index = this.#hashFunc(key);\n        let bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (let i = 0; i < bucket.length; i++) {\n            if (bucket[i].key === key) {\n                bucket.splice(i, 1);\n                this.#size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    #extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.#buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.#capacity *= this.#extendRatio;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n        this.#size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const bucket of bucketsTmp) {\n            for (const pair of bucket) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print() {\n        for (const bucket of this.#buckets) {\n            let res = [];\n            for (const pair of bucket) {\n                res.push(pair.key + ' -> ' + pair.val);\n            }\n            console.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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#size = 0;\n        this.#capacity = 4;\n        this.#loadThres = 2.0 / 3.0;\n        this.#extendRatio = 2;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key: number): number {\n        return key % this.#capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    #loadFactor(): number {\n        return this.#size / this.#capacity;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key: number): string | null {\n        const index = this.#hashFunc(key);\n        const bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                return pair.val;\n            }\n        }\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key: number, val: string): void {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.#loadFactor() > this.#loadThres) {\n            this.#extend();\n        }\n        const index = this.#hashFunc(key);\n        const 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\n        for (const pair of bucket) {\n            if (pair.key === key) {\n                pair.val = val;\n                return;\n            }\n        }\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        const pair = new Pair(key, val);\n        bucket.push(pair);\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key: number): void {\n        const index = this.#hashFunc(key);\n        let bucket = this.#buckets[index];\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for (let i = 0; i < bucket.length; i++) {\n            if (bucket[i].key === key) {\n                bucket.splice(i, 1);\n                this.#size--;\n                break;\n            }\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    #extend(): void {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.#buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.#capacity *= this.#extendRatio;\n        this.#buckets = new Array(this.#capacity).fill(null).map((x) => []);\n        this.#size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const bucket of bucketsTmp) {\n            for (const pair of bucket) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print(): void {\n        for (const bucket of this.#buckets) {\n            let res = [];\n            for (const pair of bucket) {\n                res.push(pair.key + ' -> ' + pair.val);\n            }\n            console.log(res);\n        }\n    }\n}\n
    hash_map_chaining.dart
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nclass HashMapChaining {\n  late int size; // \u952e\u503c\u5bf9\u6570\u91cf\n  late int capacity; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n  late double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n  late int extendRatio; // \u6269\u5bb9\u500d\u6570\n  late List<List<Pair>> buckets; // \u6876\u6570\u7ec4\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  HashMapChaining() {\n    size = 0;\n    capacity = 4;\n    loadThres = 2.0 / 3.0;\n    extendRatio = 2;\n    buckets = List.generate(capacity, (_) => []);\n  }\n\n  /* \u54c8\u5e0c\u51fd\u6570 */\n  int hashFunc(int key) {\n    return key % capacity;\n  }\n\n  /* \u8d1f\u8f7d\u56e0\u5b50 */\n  double loadFactor() {\n    return size / capacity;\n  }\n\n  /* \u67e5\u8be2\u64cd\u4f5c */\n  String? get(int key) {\n    int index = hashFunc(key);\n    List<Pair> bucket = buckets[index];\n    // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    for (Pair pair in bucket) {\n      if (pair.key == key) {\n        return pair.val;\n      }\n    }\n    // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de null\n    return null;\n  }\n\n  /* \u6dfb\u52a0\u64cd\u4f5c */\n  void put(int key, String val) {\n    // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n    if (loadFactor() > loadThres) {\n      extend();\n    }\n    int index = hashFunc(key);\n    List<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\n    for (Pair pair in bucket) {\n      if (pair.key == key) {\n        pair.val = val;\n        return;\n      }\n    }\n    // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n    Pair pair = Pair(key, val);\n    bucket.add(pair);\n    size++;\n  }\n\n  /* \u5220\u9664\u64cd\u4f5c */\n  void remove(int key) {\n    int index = hashFunc(key);\n    List<Pair> bucket = buckets[index];\n    // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n    for (Pair pair in bucket) {\n      if (pair.key == key) {\n        bucket.remove(pair);\n        size--;\n        break;\n      }\n    }\n  }\n\n  /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n  void extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    List<List<Pair>> bucketsTmp = buckets;\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    capacity *= extendRatio;\n    buckets = List.generate(capacity, (_) => []);\n    size = 0;\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for (List<Pair> bucket in bucketsTmp) {\n      for (Pair pair in bucket) {\n        put(pair.key, pair.val);\n      }\n    }\n  }\n\n  /* \u6253\u5370\u54c8\u5e0c\u8868 */\n  void printHashMap() {\n    for (List<Pair> bucket in buckets) {\n      List<String> res = [];\n      for (Pair pair in bucket) {\n        res.add(\"${pair.key} -> ${pair.val}\");\n      }\n      print(res);\n    }\n  }\n}\n
    hash_map_chaining.rs
    /* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapChaining {\n    size: i32,\n    capacity: i32,\n    load_thres: f32,\n    extend_ratio: i32,\n    buckets: Vec<Vec<Pair>>,\n}\n\nimpl HashMapChaining {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new() -> Self {\n        Self {\n            size: 0,\n            capacity: 4,\n            load_thres: 2.0 / 3.0,\n            extend_ratio: 2,\n            buckets: vec![vec![]; 4],\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    fn hash_func(&self, key: i32) -> usize {\n        key as usize % self.capacity as usize\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    fn load_factor(&self) -> f32 {\n        self.size as f32 / self.capacity as f32\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    fn remove(&mut self, key: i32) -> Option<String> {\n        let index = self.hash_func(key);\n        let bucket = &mut self.buckets[index];\n\n        // \u904d\u5386\u6876\uff0c\u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n        for i in 0..bucket.len() {\n            if bucket[i].key == key {\n                let pair = bucket.remove(i);\n                self.size -= 1;\n                return Some(pair.val);\n            }\n        }\n\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de None\n        None\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    fn extend(&mut self) {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let buckets_tmp = std::mem::replace(&mut self.buckets, vec![]);\n\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio;\n        self.buckets = vec![Vec::new(); self.capacity as usize];\n        self.size = 0;\n\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for bucket in buckets_tmp {\n            for pair in bucket {\n                self.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    fn print(&self) {\n        for bucket in &self.buckets {\n            let mut res = Vec::new();\n            for pair in bucket {\n                res.push(format!(\"{} -> {}\", pair.key, pair.val));\n            }\n            println!(\"{:?}\", res);\n        }\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    fn put(&mut self, key: i32, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if self.load_factor() > self.load_thres {\n            self.extend();\n        }\n\n        let index = self.hash_func(key);\n        let bucket = &mut self.buckets[index];\n\n        // \u904d\u5386\u6876\uff0c\u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n        for pair in bucket {\n            if pair.key == key {\n                pair.val = val.clone();\n                return;\n            }\n        }\n        let bucket = &mut self.buckets[index];\n\n        // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u5c3e\u90e8\n        let pair = Pair {\n            key,\n            val: val.clone(),\n        };\n        bucket.push(pair);\n        self.size += 1;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    fn get(&self, key: i32) -> Option<&str> {\n        let index = self.hash_func(key);\n        let bucket = &self.buckets[index];\n\n        // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        for pair in bucket {\n            if pair.key == key {\n                return Some(&pair.val);\n            }\n        }\n\n        // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de None\n        None\n    }\n}\n
    hash_map_chaining.c
    /* \u94fe\u8868\u8282\u70b9 */\ntypedef struct Node {\n    Pair *pair;\n    struct Node *next;\n} Node;\n\n/* \u94fe\u5f0f\u5730\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\n    int size;         // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio;  // \u6269\u5bb9\u500d\u6570\n    Node **buckets;   // \u6876\u6570\u7ec4\n} HashMapChaining;\n\n/* \u6784\u9020\u51fd\u6570 */\nHashMapChaining *newHashMapChaining() {\n    HashMapChaining *hashMap = (HashMapChaining *)malloc(sizeof(HashMapChaining));\n    hashMap->size = 0;\n    hashMap->capacity = 4;\n    hashMap->loadThres = 2.0 / 3.0;\n    hashMap->extendRatio = 2;\n    hashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\n    for (int i = 0; i < hashMap->capacity; i++) {\n        hashMap->buckets[i] = NULL;\n    }\n    return hashMap;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapChaining(HashMapChaining *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Node *cur = hashMap->buckets[i];\n        while (cur) {\n            Node *tmp = cur;\n            cur = cur->next;\n            free(tmp->pair);\n            free(tmp);\n        }\n    }\n    free(hashMap->buckets);\n    free(hashMap);\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapChaining *hashMap, int key) {\n    return key % hashMap->capacity;\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapChaining *hashMap) {\n    return (double)hashMap->size / (double)hashMap->capacity;\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapChaining *hashMap, int key) {\n    int index = hashFunc(hashMap, key);\n    // \u904d\u5386\u6876\uff0c\u82e5\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    Node *cur = hashMap->buckets[index];\n    while (cur) {\n        if (cur->pair->key == key) {\n            return cur->pair->val;\n        }\n        cur = cur->next;\n    }\n    return \"\"; // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n}\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\n    if (loadFactor(hashMap) > hashMap->loadThres) {\n        extend(hashMap);\n    }\n    int 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\n    Node *cur = hashMap->buckets[index];\n    while (cur) {\n        if (cur->pair->key == key) {\n            strcpy(cur->pair->val, val); // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val \u5e76\u8fd4\u56de\n            return;\n        }\n        cur = cur->next;\n    }\n    // \u82e5\u65e0\u8be5 key \uff0c\u5219\u5c06\u952e\u503c\u5bf9\u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n    Pair *newPair = (Pair *)malloc(sizeof(Pair));\n    newPair->key = key;\n    strcpy(newPair->val, val);\n    Node *newNode = (Node *)malloc(sizeof(Node));\n    newNode->pair = newPair;\n    newNode->next = hashMap->buckets[index];\n    hashMap->buckets[index] = newNode;\n    hashMap->size++;\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapChaining *hashMap) {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    int oldCapacity = hashMap->capacity;\n    Node **oldBuckets = hashMap->buckets;\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    hashMap->capacity *= hashMap->extendRatio;\n    hashMap->buckets = (Node **)malloc(hashMap->capacity * sizeof(Node *));\n    for (int i = 0; i < hashMap->capacity; i++) {\n        hashMap->buckets[i] = NULL;\n    }\n    hashMap->size = 0;\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for (int i = 0; i < oldCapacity; i++) {\n        Node *cur = oldBuckets[i];\n        while (cur) {\n            put(hashMap, cur->pair->key, cur->pair->val);\n            Node *temp = cur;\n            cur = cur->next;\n            // \u91ca\u653e\u5185\u5b58\n            free(temp->pair);\n            free(temp);\n        }\n    }\n\n    free(oldBuckets);\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapChaining *hashMap, int key) {\n    int index = hashFunc(hashMap, key);\n    Node *cur = hashMap->buckets[index];\n    Node *pre = NULL;\n    while (cur) {\n        if (cur->pair->key == key) {\n            // \u4ece\u4e2d\u5220\u9664\u952e\u503c\u5bf9\n            if (pre) {\n                pre->next = cur->next;\n            } else {\n                hashMap->buckets[index] = cur->next;\n            }\n            // \u91ca\u653e\u5185\u5b58\n            free(cur->pair);\n            free(cur);\n            hashMap->size--;\n            return;\n        }\n        pre = cur;\n        cur = cur->next;\n    }\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapChaining *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Node *cur = hashMap->buckets[i];\n        printf(\"[\");\n        while (cur) {\n            printf(\"%d -> %s, \", cur->pair->key, cur->pair->val);\n            cur = cur->next;\n        }\n        printf(\"]\\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\u548c\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\u8fdb\u884c\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 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\uff08\u7ebf\u6027\u63a2\u6d4b\uff09\u54c8\u5e0c\u8868\u7684\u952e\u503c\u5bf9\u5206\u5e03

    \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 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\uff0cNone \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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self.size = 0  # \u952e\u503c\u5bf9\u6570\u91cf\n        self.capacity = 4  # \u54c8\u5e0c\u8868\u5bb9\u91cf\n        self.load_thres = 2.0 / 3.0  # \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        self.extend_ratio = 2  # \u6269\u5bb9\u500d\u6570\n        self.buckets: list[Pair | None] = [None] * self.capacity  # \u6876\u6570\u7ec4\n        self.TOMBSTONE = Pair(-1, \"-1\")  # \u5220\u9664\u6807\u8bb0\n\n    def hash_func(self, key: int) -> int:\n        \"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\n        return key % self.capacity\n\n    def load_factor(self) -> float:\n        \"\"\"\u8d1f\u8f7d\u56e0\u5b50\"\"\"\n        return self.size / self.capacity\n\n    def find_bucket(self, key: int) -> int:\n        \"\"\"\u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\"\"\"\n        index = self.hash_func(key)\n        first_tombstone = -1\n        # \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while self.buckets[index] is not None:\n            # \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if 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\u5904\n                if first_tombstone != -1:\n                    self.buckets[first_tombstone] = self.buckets[index]\n                    self.buckets[index] = self.TOMBSTONE\n                    return first_tombstone  # \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                return index  # \u8fd4\u56de\u6876\u7d22\u5f15\n            # \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if first_tombstone == -1 and self.buckets[index] is self.TOMBSTONE:\n                first_tombstone = index\n            # \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % self.capacity\n        # \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return index if first_tombstone == -1 else first_tombstone\n\n    def get(self, key: int) -> str:\n        \"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n        # \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        index = self.find_bucket(key)\n        # \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if self.buckets[index] not in [None, self.TOMBSTONE]:\n            return self.buckets[index].val\n        # \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de None\n        return None\n\n    def 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\n        if self.load_factor() > self.load_thres:\n            self.extend()\n        # \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        index = self.find_bucket(key)\n        # \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if self.buckets[index] not in [None, self.TOMBSTONE]:\n            self.buckets[index].val = val\n            return\n        # \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        self.buckets[index] = Pair(key, val)\n        self.size += 1\n\n    def remove(self, key: int):\n        \"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n        # \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        index = self.find_bucket(key)\n        # \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if self.buckets[index] not in [None, self.TOMBSTONE]:\n            self.buckets[index] = self.TOMBSTONE\n            self.size -= 1\n\n    def extend(self):\n        \"\"\"\u6269\u5bb9\u54c8\u5e0c\u8868\"\"\"\n        # \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        buckets_tmp = self.buckets\n        # \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio\n        self.buckets = [None] * self.capacity\n        self.size = 0\n        # \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for pair in buckets_tmp:\n            if pair not in [None, self.TOMBSTONE]:\n                self.put(pair.key, pair.val)\n\n    def print(self):\n        \"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\n        for pair in self.buckets:\n            if pair is None:\n                print(\"None\")\n            elif pair is self.TOMBSTONE:\n                print(\"TOMBSTONE\")\n            else:\n                print(pair.key, \"->\", pair.val)\n
    hash_map_open_addressing.cpp
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n  private:\n    int size;                             // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity = 4;                     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    const double loadThres = 2.0 / 3.0;     // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    const int extendRatio = 2;            // \u6269\u5bb9\u500d\u6570\n    vector<Pair *> buckets;               // \u6876\u6570\u7ec4\n    Pair *TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    HashMapOpenAddressing() : size(0), buckets(capacity, nullptr) {\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~HashMapOpenAddressing() {\n        for (Pair *pair : buckets) {\n            if (pair != nullptr && pair != TOMBSTONE) {\n                delete pair;\n            }\n        }\n        delete TOMBSTONE;\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double loadFactor() {\n        return (double)size / capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    int findBucket(int key) {\n        int index = hashFunc(key);\n        int firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (buckets[index] != nullptr) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone != -1) {\n                    buckets[firstTombstone] = buckets[index];\n                    buckets[index] = TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    string get(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\n            return buckets[index]->val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n        return \"\";\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\n            buckets[index]->val = val;\n            return;\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\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (buckets[index] != nullptr && buckets[index] != TOMBSTONE) {\n            delete buckets[index];\n            buckets[index] = TOMBSTONE;\n            size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        vector<Pair *> bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = vector<Pair *>(capacity, nullptr);\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (Pair *pair : bucketsTmp) {\n            if (pair != nullptr && pair != TOMBSTONE) {\n                put(pair->key, pair->val);\n                delete pair;\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (Pair *pair : buckets) {\n            if (pair == nullptr) {\n                cout << \"nullptr\" << endl;\n            } else if (pair == TOMBSTONE) {\n                cout << \"TOMBSTONE\" << endl;\n            } else {\n                cout << pair->key << \" -> \" << pair->val << endl;\n            }\n        }\n    }\n};\n
    hash_map_open_addressing.java
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n    private int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    private int capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    private final double loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    private final int extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n    private Pair[] buckets; // \u6876\u6570\u7ec4\n    private final Pair TOMBSTONE = new Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapOpenAddressing() {\n        size = 0;\n        buckets = new Pair[capacity];\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private int hashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    private double loadFactor() {\n        return (double) size / capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    private int findBucket(int key) {\n        int index = hashFunc(key);\n        int firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (buckets[index] != null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone != -1) {\n                    buckets[firstTombstone] = buckets[index];\n                    buckets[index] = TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public String get(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            return buckets[index].val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void put(int key, String val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (loadFactor() > loadThres) {\n            extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index].val = val;\n            return;\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\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void remove(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index] = TOMBSTONE;\n            size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    private void extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        Pair[] bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new Pair[capacity];\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (Pair pair : bucketsTmp) {\n            if (pair != null && pair != TOMBSTONE) {\n                put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void print() {\n        for (Pair pair : buckets) {\n            if (pair == null) {\n                System.out.println(\"null\");\n            } else if (pair == TOMBSTONE) {\n                System.out.println(\"TOMBSTONE\");\n            } else {\n                System.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 {\n    int size; // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n    Pair[] buckets; // \u6876\u6570\u7ec4\n    Pair TOMBSTONE = new(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public HashMapOpenAddressing() {\n        size = 0;\n        buckets = new Pair[capacity];\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int HashFunc(int key) {\n        return key % capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    double LoadFactor() {\n        return (double)size / capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    int FindBucket(int key) {\n        int index = HashFunc(key);\n        int firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (buckets[index] != null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone != -1) {\n                    buckets[firstTombstone] = buckets[index];\n                    buckets[index] = TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (firstTombstone == -1 && buckets[index] == TOMBSTONE) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public string? Get(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = FindBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            return buckets[index].val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void Put(int key, string val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (LoadFactor() > loadThres) {\n            Extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = FindBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index].val = val;\n            return;\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\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void Remove(int key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        int index = FindBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (buckets[index] != null && buckets[index] != TOMBSTONE) {\n            buckets[index] = TOMBSTONE;\n            size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    void Extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        Pair[] bucketsTmp = buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio;\n        buckets = new Pair[capacity];\n        size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        foreach (Pair pair in bucketsTmp) {\n            if (pair != null && pair != TOMBSTONE) {\n                Put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void Print() {\n        foreach (Pair pair in buckets) {\n            if (pair == null) {\n                Console.WriteLine(\"null\");\n            } else if (pair == TOMBSTONE) {\n                Console.WriteLine(\"TOMBSTONE\");\n            } else {\n                Console.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 {\n    size        int     // \u952e\u503c\u5bf9\u6570\u91cf\n    capacity    int     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    loadThres   float64 // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    extendRatio int     // \u6269\u5bb9\u500d\u6570\n    buckets     []pair  // \u6876\u6570\u7ec4\n    removed     pair    // \u5220\u9664\u6807\u8bb0\n}\n\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newHashMapOpenAddressing() *hashMapOpenAddressing {\n    buckets := make([]pair, 4)\n    return &hashMapOpenAddressing{\n        size:        0,\n        capacity:    4,\n        loadThres:   2.0 / 3.0,\n        extendRatio: 2,\n        buckets:     buckets,\n        removed: pair{\n            key: -1,\n            val: \"-1\",\n        },\n    }\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (m *hashMapOpenAddressing) hashFunc(key int) int {\n    return key % m.capacity\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\nfunc (m *hashMapOpenAddressing) loadFactor() float64 {\n    return float64(m.size) / float64(m.capacity)\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) get(key int) string {\n    idx := m.hashFunc(key)\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\n    for i := 0; i < m.capacity; i++ {\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        j := (idx + i) % m.capacity\n        // \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u8fd4\u56de null\n        if m.buckets[j] == (pair{}) {\n            return \"\"\n        }\n        // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if m.buckets[j].key == key && m.buckets[j] != m.removed {\n            return m.buckets[j].val\n        }\n    }\n    // \u82e5\u672a\u627e\u5230 key \uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n    return \"\"\n}\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\n    if m.loadFactor() > m.loadThres {\n        m.extend()\n    }\n    idx := m.hashFunc(key)\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u4ece index \u5f00\u59cb\u5411\u540e\u904d\u5386\n    for i := 0; i < m.capacity; i++ {\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        j := (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\n        if m.buckets[j] == (pair{}) || m.buckets[j] == m.removed {\n            m.buckets[j] = pair{\n                key: key,\n                val: val,\n            }\n            m.size += 1\n            return\n        }\n        // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u66f4\u65b0\u5bf9\u5e94 val\n        if m.buckets[j].key == key {\n            m.buckets[j].val = val\n            return\n        }\n    }\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (m *hashMapOpenAddressing) remove(key int) {\n    idx := 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\n    for i := 0; i < m.capacity; i++ {\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        j := (idx + i) % m.capacity\n        // \u82e5\u9047\u5230\u7a7a\u6876\uff0c\u8bf4\u660e\u65e0\u6b64 key \uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n        if m.buckets[j] == (pair{}) {\n            return\n        }\n        // \u82e5\u9047\u5230\u6307\u5b9a key \uff0c\u5219\u6807\u8bb0\u5220\u9664\u5e76\u8fd4\u56de\n        if m.buckets[j].key == key {\n            m.buckets[j] = m.removed\n            m.size -= 1\n        }\n    }\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    tmpBuckets := make([]pair, len(m.buckets))\n    copy(tmpBuckets, m.buckets)\n\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    m.capacity *= m.extendRatio\n    m.buckets = make([]pair, m.capacity)\n    m.size = 0\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for _, p := range tmpBuckets {\n        if p != (pair{}) && p != m.removed {\n            m.put(p.key, p.val)\n        }\n    }\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (m *hashMapOpenAddressing) print() {\n    for _, p := range m.buckets {\n        if p != (pair{}) {\n            fmt.Println(strconv.Itoa(p.key) + \" -> \" + p.val)\n        } else {\n            fmt.Println(\"nil\")\n        }\n    }\n}\n
    hash_map_open_addressing.swift
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n    var size: Int // \u952e\u503c\u5bf9\u6570\u91cf\n    var capacity: Int // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    var loadThres: Double // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    var extendRatio: Int // \u6269\u5bb9\u500d\u6570\n    var buckets: [Pair?] // \u6876\u6570\u7ec4\n    var TOMBSTONE: Pair // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init() {\n        size = 0\n        capacity = 4\n        loadThres = 2.0 / 3.0\n        extendRatio = 2\n        buckets = Array(repeating: nil, count: capacity)\n        TOMBSTONE = Pair(key: -1, val: \"-1\")\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    func hashFunc(key: Int) -> Int {\n        key % capacity\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    func loadFactor() -> Double {\n        Double(size / capacity)\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    func findBucket(key: Int) -> Int {\n        var index = hashFunc(key: key)\n        var firstTombstone = -1\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while buckets[index] != nil {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if 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\u5904\n                if firstTombstone != -1 {\n                    buckets[firstTombstone] = buckets[index]\n                    buckets[index] = TOMBSTONE\n                    return firstTombstone // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if firstTombstone == -1 && buckets[index] == TOMBSTONE {\n                firstTombstone = index\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % capacity\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone == -1 ? index : firstTombstone\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    func get(key: Int) -> String? {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = findBucket(key: key)\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if buckets[index] != nil, buckets[index] != TOMBSTONE {\n            return buckets[index]!.val\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return nil\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    func put(key: Int, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if loadFactor() > loadThres {\n            extend()\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = findBucket(key: key)\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if buckets[index] != nil, buckets[index] != TOMBSTONE {\n            buckets[index]!.val = val\n            return\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        buckets[index] = Pair(key: key, val: val)\n        size += 1\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    func remove(key: Int) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = findBucket(key: key)\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if buckets[index] != nil, buckets[index] != TOMBSTONE {\n            buckets[index] = TOMBSTONE\n            size -= 1\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    func extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let bucketsTmp = buckets\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        capacity *= extendRatio\n        buckets = Array(repeating: nil, count: capacity)\n        size = 0\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for pair in bucketsTmp {\n            if let pair, pair != TOMBSTONE {\n                put(key: pair.key, val: pair.val)\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    func print() {\n        for pair in buckets {\n            if pair == nil {\n                Swift.print(\"null\")\n            } else if pair == TOMBSTONE {\n                Swift.print(\"TOMBSTONE\")\n            } else {\n                Swift.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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.#size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\n        this.#capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n        this.#loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        this.#extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n        this.#buckets = Array(this.#capacity).fill(null); // \u6876\u6570\u7ec4\n        this.#TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key) {\n        return key % this.#capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    #loadFactor() {\n        return this.#size / this.#capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    #findBucket(key) {\n        let index = this.#hashFunc(key);\n        let firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (this.#buckets[index] !== null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone !== -1) {\n                    this.#buckets[firstTombstone] = this.#buckets[index];\n                    this.#buckets[index] = this.#TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (\n                firstTombstone === -1 &&\n                this.#buckets[index] === this.#TOMBSTONE\n            ) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % this.#capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone === -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.#findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (\n            this.#buckets[index] !== null &&\n            this.#buckets[index] !== this.#TOMBSTONE\n        ) {\n            return this.#buckets[index].val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key, val) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.#loadFactor() > this.#loadThres) {\n            this.#extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.#findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (\n            this.#buckets[index] !== null &&\n            this.#buckets[index] !== this.#TOMBSTONE\n        ) {\n            this.#buckets[index].val = val;\n            return;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        this.#buckets[index] = new Pair(key, val);\n        this.#size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.#findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (\n            this.#buckets[index] !== null &&\n            this.#buckets[index] !== this.#TOMBSTONE\n        ) {\n            this.#buckets[index] = this.#TOMBSTONE;\n            this.#size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    #extend() {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.#buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.#capacity *= this.#extendRatio;\n        this.#buckets = Array(this.#capacity).fill(null);\n        this.#size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const pair of bucketsTmp) {\n            if (pair !== null && pair !== this.#TOMBSTONE) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print() {\n        for (const pair of this.#buckets) {\n            if (pair === null) {\n                console.log('null');\n            } else if (pair === this.#TOMBSTONE) {\n                console.log('TOMBSTONE');\n            } else {\n                console.log(pair.key + ' -> ' + pair.val);\n            }\n        }\n    }\n}\n
    hash_map_open_addressing.ts
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n    private size: number; // \u952e\u503c\u5bf9\u6570\u91cf\n    private capacity: number; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    private loadThres: number; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    private extendRatio: number; // \u6269\u5bb9\u500d\u6570\n    private buckets: Array<Pair | null>; // \u6876\u6570\u7ec4\n    private TOMBSTONE: Pair; // \u5220\u9664\u6807\u8bb0\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor() {\n        this.size = 0; // \u952e\u503c\u5bf9\u6570\u91cf\n        this.capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n        this.loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n        this.extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n        this.buckets = Array(this.capacity).fill(null); // \u6876\u6570\u7ec4\n        this.TOMBSTONE = new Pair(-1, '-1'); // \u5220\u9664\u6807\u8bb0\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private hashFunc(key: number): number {\n        return key % this.capacity;\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    private loadFactor(): number {\n        return this.size / this.capacity;\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    private findBucket(key: number): number {\n        let index = this.hashFunc(key);\n        let firstTombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while (this.buckets[index] !== null) {\n            // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if (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\u5904\n                if (firstTombstone !== -1) {\n                    this.buckets[firstTombstone] = this.buckets[index];\n                    this.buckets[index] = this.TOMBSTONE;\n                    return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if (\n                firstTombstone === -1 &&\n                this.buckets[index] === this.TOMBSTONE\n            ) {\n                firstTombstone = index;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % this.capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        return firstTombstone === -1 ? index : firstTombstone;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key: number): string | null {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if (\n            this.buckets[index] !== null &&\n            this.buckets[index] !== this.TOMBSTONE\n        ) {\n            return this.buckets[index]!.val;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n        return null;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    put(key: number, val: string): void {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if (this.loadFactor() > this.loadThres) {\n            this.extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if (\n            this.buckets[index] !== null &&\n            this.buckets[index] !== this.TOMBSTONE\n        ) {\n            this.buckets[index]!.val = val;\n            return;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        this.buckets[index] = new Pair(key, val);\n        this.size++;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    remove(key: number): void {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        const index = this.findBucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if (\n            this.buckets[index] !== null &&\n            this.buckets[index] !== this.TOMBSTONE\n        ) {\n            this.buckets[index] = this.TOMBSTONE;\n            this.size--;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    private extend(): void {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        const bucketsTmp = this.buckets;\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        this.capacity *= this.extendRatio;\n        this.buckets = Array(this.capacity).fill(null);\n        this.size = 0;\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for (const pair of bucketsTmp) {\n            if (pair !== null && pair !== this.TOMBSTONE) {\n                this.put(pair.key, pair.val);\n            }\n        }\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print(): void {\n        for (const pair of this.buckets) {\n            if (pair === null) {\n                console.log('null');\n            } else if (pair === this.TOMBSTONE) {\n                console.log('TOMBSTONE');\n            } else {\n                console.log(pair.key + ' -> ' + pair.val);\n            }\n        }\n    }\n}\n
    hash_map_open_addressing.dart
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nclass HashMapOpenAddressing {\n  late int _size; // \u952e\u503c\u5bf9\u6570\u91cf\n  int _capacity = 4; // \u54c8\u5e0c\u8868\u5bb9\u91cf\n  double _loadThres = 2.0 / 3.0; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n  int _extendRatio = 2; // \u6269\u5bb9\u500d\u6570\n  late List<Pair?> _buckets; // \u6876\u6570\u7ec4\n  Pair _TOMBSTONE = Pair(-1, \"-1\"); // \u5220\u9664\u6807\u8bb0\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  HashMapOpenAddressing() {\n    _size = 0;\n    _buckets = List.generate(_capacity, (index) => null);\n  }\n\n  /* \u54c8\u5e0c\u51fd\u6570 */\n  int hashFunc(int key) {\n    return key % _capacity;\n  }\n\n  /* \u8d1f\u8f7d\u56e0\u5b50 */\n  double loadFactor() {\n    return _size / _capacity;\n  }\n\n  /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n  int findBucket(int key) {\n    int index = hashFunc(key);\n    int firstTombstone = -1;\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n    while (_buckets[index] != null) {\n      // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n      if (_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\u5904\n        if (firstTombstone != -1) {\n          _buckets[firstTombstone] = _buckets[index];\n          _buckets[index] = _TOMBSTONE;\n          return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n        }\n        return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n      }\n      // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n      if (firstTombstone == -1 && _buckets[index] == _TOMBSTONE) {\n        firstTombstone = index;\n      }\n      // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n      index = (index + 1) % _capacity;\n    }\n    // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n    return firstTombstone == -1 ? index : firstTombstone;\n  }\n\n  /* \u67e5\u8be2\u64cd\u4f5c */\n  String? get(int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    if (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n      return _buckets[index]!.val;\n    }\n    // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de null\n    return null;\n  }\n\n  /* \u6dfb\u52a0\u64cd\u4f5c */\n  void put(int key, String val) {\n    // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n    if (loadFactor() > _loadThres) {\n      extend();\n    }\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n    if (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n      _buckets[index]!.val = val;\n      return;\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\n  /* \u5220\u9664\u64cd\u4f5c */\n  void remove(int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n    if (_buckets[index] != null && _buckets[index] != _TOMBSTONE) {\n      _buckets[index] = _TOMBSTONE;\n      _size--;\n    }\n  }\n\n  /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n  void extend() {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    List<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\n    for (Pair? pair in bucketsTmp) {\n      if (pair != null && pair != _TOMBSTONE) {\n        put(pair.key, pair.val);\n      }\n    }\n  }\n\n  /* \u6253\u5370\u54c8\u5e0c\u8868 */\n  void printHashMap() {\n    for (Pair? pair in _buckets) {\n      if (pair == null) {\n        print(\"null\");\n      } else if (pair == _TOMBSTONE) {\n        print(\"TOMBSTONE\");\n      } else {\n        print(\"${pair.key} -> ${pair.val}\");\n      }\n    }\n  }\n}\n
    hash_map_open_addressing.rs
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\nstruct HashMapOpenAddressing {\n    size: usize,                    // \u952e\u503c\u5bf9\u6570\u91cf\n    capacity: usize,                // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    load_thres: f64,                // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    extend_ratio: usize,            // \u6269\u5bb9\u500d\u6570\n    buckets: Vec<Option<Pair>>,     // \u6876\u6570\u7ec4\n    TOMBSTONE: Option<Pair>,        // \u5220\u9664\u6807\u8bb0\n}\n\n\nimpl HashMapOpenAddressing {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new() -> Self {\n        Self {\n            size: 0,\n            capacity: 4,\n            load_thres: 2.0 / 3.0,\n            extend_ratio: 2,\n            buckets: vec![None; 4],\n            TOMBSTONE: Some(Pair {key: -1, val: \"-1\".to_string()}),\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    fn hash_func(&self, key: i32) -> usize {\n        (key % self.capacity as i32) as usize\n    }\n\n    /* \u8d1f\u8f7d\u56e0\u5b50 */\n    fn load_factor(&self) -> f64 {\n        self.size as f64 / self.capacity as f64\n    }\n\n    /* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\n    fn find_bucket(&mut self, key: i32) -> usize {\n        let mut index = self.hash_func(key);\n        let mut first_tombstone = -1;\n        // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n        while self.buckets[index].is_some() {\n            // \u82e5\u9047\u5230 key\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n            if 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\n                if first_tombstone != -1 {\n                    self.buckets[first_tombstone as usize] = self.buckets[index].take();\n                    self.buckets[index] = self.TOMBSTONE.clone();\n                    return first_tombstone as usize;    // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n                }\n                return index;   // \u8fd4\u56de\u6876\u7d22\u5f15\n            }\n            // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n            if first_tombstone == -1 && self.buckets[index] == self.TOMBSTONE {\n                first_tombstone = index as i32;\n            }\n            // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n            index = (index + 1) % self.capacity;\n        }\n        // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n        if first_tombstone == -1 { index } else { first_tombstone as usize }\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    fn get(&mut self, key: i32) -> Option<&str> {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = self.find_bucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n        if self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\n            return 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\n        None\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    fn put(&mut self, key: i32, val: String) {\n        // \u5f53\u8d1f\u8f7d\u56e0\u5b50\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u6267\u884c\u6269\u5bb9\n        if self.load_factor() > self.load_thres {\n            self.extend();\n        }\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = self.find_bucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n        if self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\n            self.buckets[index].as_mut().unwrap().val = val;\n            return;\n        }\n        // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n        self.buckets[index] = Some(Pair { key, val });\n        self.size += 1;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    fn remove(&mut self, key: i32) {\n        // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        let index = self.find_bucket(key);\n        // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n        if self.buckets[index].is_some() && self.buckets[index] != self.TOMBSTONE {\n            self.buckets[index] = self.TOMBSTONE.clone();\n            self.size -= 1;\n        }\n    }\n\n    /* \u6269\u5bb9\u54c8\u5e0c\u8868 */\n    fn extend(&mut self) {\n        // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n        let buckets_tmp = self.buckets.clone();\n        // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n        self.capacity *= self.extend_ratio;\n        self.buckets = vec![None; self.capacity];\n        self.size = 0;\n\n        // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n        for pair in buckets_tmp {\n            if pair.is_none() || pair == self.TOMBSTONE {\n                continue;\n            }\n            let pair = pair.unwrap();\n\n            self.put(pair.key, pair.val);\n        }\n    }\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    fn print(&self) {\n        for pair in &self.buckets {\n            if pair.is_none() {\n                println!(\"null\");\n            } else if pair == &self.TOMBSTONE {\n                println!(\"TOMBSTONE\");\n            } else {\n                let pair = pair.as_ref().unwrap();\n                println!(\"{} -> {}\", pair.key, pair.val);\n            }\n        }\n    }\n}\n
    hash_map_open_addressing.c
    /* \u5f00\u653e\u5bfb\u5740\u54c8\u5e0c\u8868 */\ntypedef struct {\n    int size;         // \u952e\u503c\u5bf9\u6570\u91cf\n    int capacity;     // \u54c8\u5e0c\u8868\u5bb9\u91cf\n    double loadThres; // \u89e6\u53d1\u6269\u5bb9\u7684\u8d1f\u8f7d\u56e0\u5b50\u9608\u503c\n    int extendRatio;  // \u6269\u5bb9\u500d\u6570\n    Pair **buckets;   // \u6876\u6570\u7ec4\n    Pair *TOMBSTONE;  // \u5220\u9664\u6807\u8bb0\n} HashMapOpenAddressing;\n\n/* \u6784\u9020\u51fd\u6570 */\nHashMapOpenAddressing *newHashMapOpenAddressing() {\n    HashMapOpenAddressing *hashMap = (HashMapOpenAddressing *)malloc(sizeof(HashMapOpenAddressing));\n    hashMap->size = 0;\n    hashMap->capacity = 4;\n    hashMap->loadThres = 2.0 / 3.0;\n    hashMap->extendRatio = 2;\n    hashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\n    hashMap->TOMBSTONE = (Pair *)malloc(sizeof(Pair));\n    hashMap->TOMBSTONE->key = -1;\n    hashMap->TOMBSTONE->val = \"-1\";\n\n    return hashMap;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delHashMapOpenAddressing(HashMapOpenAddressing *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Pair *pair = hashMap->buckets[i];\n        if (pair != NULL && pair != hashMap->TOMBSTONE) {\n            free(pair->val);\n            free(pair);\n        }\n    }\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nint hashFunc(HashMapOpenAddressing *hashMap, int key) {\n    return key % hashMap->capacity;\n}\n\n/* \u8d1f\u8f7d\u56e0\u5b50 */\ndouble loadFactor(HashMapOpenAddressing *hashMap) {\n    return (double)hashMap->size / (double)hashMap->capacity;\n}\n\n/* \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15 */\nint findBucket(HashMapOpenAddressing *hashMap, int key) {\n    int index = hashFunc(hashMap, key);\n    int firstTombstone = -1;\n    // \u7ebf\u6027\u63a2\u6d4b\uff0c\u5f53\u9047\u5230\u7a7a\u6876\u65f6\u8df3\u51fa\n    while (hashMap->buckets[index] != NULL) {\n        // \u82e5\u9047\u5230 key \uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n        if (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\u5904\n            if (firstTombstone != -1) {\n                hashMap->buckets[firstTombstone] = hashMap->buckets[index];\n                hashMap->buckets[index] = hashMap->TOMBSTONE;\n                return firstTombstone; // \u8fd4\u56de\u79fb\u52a8\u540e\u7684\u6876\u7d22\u5f15\n            }\n            return index; // \u8fd4\u56de\u6876\u7d22\u5f15\n        }\n        // \u8bb0\u5f55\u9047\u5230\u7684\u9996\u4e2a\u5220\u9664\u6807\u8bb0\n        if (firstTombstone == -1 && hashMap->buckets[index] == hashMap->TOMBSTONE) {\n            firstTombstone = index;\n        }\n        // \u8ba1\u7b97\u6876\u7d22\u5f15\uff0c\u8d8a\u8fc7\u5c3e\u90e8\u5219\u8fd4\u56de\u5934\u90e8\n        index = (index + 1) % hashMap->capacity;\n    }\n    // \u82e5 key \u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u6dfb\u52a0\u70b9\u7684\u7d22\u5f15\n    return firstTombstone == -1 ? index : firstTombstone;\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nchar *get(HashMapOpenAddressing *hashMap, int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(hashMap, key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8fd4\u56de\u5bf9\u5e94 val\n    if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\n        return hashMap->buckets[index]->val;\n    }\n    // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u8fd4\u56de\u7a7a\u5b57\u7b26\u4e32\n    return \"\";\n}\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\n    if (loadFactor(hashMap) > hashMap->loadThres) {\n        extend(hashMap);\n    }\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(hashMap, key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u8986\u76d6 val \u5e76\u8fd4\u56de\n    if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\n        free(hashMap->buckets[index]->val);\n        hashMap->buckets[index]->val = (char *)malloc(sizeof(strlen(val) + 1));\n        strcpy(hashMap->buckets[index]->val, val);\n        hashMap->buckets[index]->val[strlen(val)] = '\\0';\n        return;\n    }\n    // \u82e5\u952e\u503c\u5bf9\u4e0d\u5b58\u5728\uff0c\u5219\u6dfb\u52a0\u8be5\u952e\u503c\u5bf9\n    Pair *pair = (Pair *)malloc(sizeof(Pair));\n    pair->key = key;\n    pair->val = (char *)malloc(sizeof(strlen(val) + 1));\n    strcpy(pair->val, val);\n    pair->val[strlen(val)] = '\\0';\n\n    hashMap->buckets[index] = pair;\n    hashMap->size++;\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(HashMapOpenAddressing *hashMap, int key) {\n    // \u641c\u7d22 key \u5bf9\u5e94\u7684\u6876\u7d22\u5f15\n    int index = findBucket(hashMap, key);\n    // \u82e5\u627e\u5230\u952e\u503c\u5bf9\uff0c\u5219\u7528\u5220\u9664\u6807\u8bb0\u8986\u76d6\u5b83\n    if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) {\n        Pair *pair = hashMap->buckets[index];\n        free(pair->val);\n        free(pair);\n        hashMap->buckets[index] = hashMap->TOMBSTONE;\n        hashMap->size--;\n    }\n}\n\n/* \u6269\u5bb9\u54c8\u5e0c\u8868 */\nvoid extend(HashMapOpenAddressing *hashMap) {\n    // \u6682\u5b58\u539f\u54c8\u5e0c\u8868\n    Pair **bucketsTmp = hashMap->buckets;\n    int oldCapacity = hashMap->capacity;\n    // \u521d\u59cb\u5316\u6269\u5bb9\u540e\u7684\u65b0\u54c8\u5e0c\u8868\n    hashMap->capacity *= hashMap->extendRatio;\n    hashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);\n    hashMap->size = 0;\n    // \u5c06\u952e\u503c\u5bf9\u4ece\u539f\u54c8\u5e0c\u8868\u642c\u8fd0\u81f3\u65b0\u54c8\u5e0c\u8868\n    for (int i = 0; i < oldCapacity; i++) {\n        Pair *pair = bucketsTmp[i];\n        if (pair != NULL && pair != hashMap->TOMBSTONE) {\n            put(hashMap, pair->key, pair->val);\n            free(pair->val);\n            free(pair);\n        }\n    }\n    free(bucketsTmp);\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(HashMapOpenAddressing *hashMap) {\n    for (int i = 0; i < hashMap->capacity; i++) {\n        Pair *pair = hashMap->buckets[i];\n        if (pair == NULL) {\n            printf(\"NULL\\n\");\n        } else if (pair == hashMap->TOMBSTONE) {\n            printf(\"TOMBSTONE\\n\");\n        } else {\n            printf(\"%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\u63a2\u6d4b\u6b21\u6570\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\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\u4f4d\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\u4f4d\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 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\u79cd\u7f16\u7a0b\u8bed\u8a00\u91c7\u53d6\u4e86\u4e0d\u540c\u7684\u54c8\u5e0c\u8868\u5b9e\u73b0\u7b56\u7565\uff0c\u4e0b\u9762\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\uff1b\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\u5b83\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\u4e2d\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\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\n# \u67e5\u8be2\u64cd\u4f5c\n# \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname: str = hmap[15937]\n\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n\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\n/* \u6dfb\u52a0\u64cd\u4f5c */\n// \u5728\u54c8\u5e0c\u8868\u4e2d\u6dfb\u52a0\u952e\u503c\u5bf9 (key, value)\nmap.put(12836, \"\u5c0f\u54c8\");   \nmap.put(15937, \"\u5c0f\u5570\");   \nmap.put(16750, \"\u5c0f\u7b97\");   \nmap.put(13276, \"\u5c0f\u6cd5\");\nmap.put(10583, \"\u5c0f\u9e2d\");\n\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map.get(15937);\n\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nstring name = map[15937];\n\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nname := hmap[15937]\n\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map[15937]!\n\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nlet name = map.get(15937);\n\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\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\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\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\n/* \u67e5\u8be2\u64cd\u4f5c */\n// \u5411\u54c8\u5e0c\u8868\u4e2d\u8f93\u5165\u952e key \uff0c\u5f97\u5230\u503c value\nString name = map[15937];\n\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\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nlet mut map: HashMap<i32, String> = HashMap::new();\n\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\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\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():\n    print(key, \"->\", value)\n# \u5355\u72ec\u904d\u5386\u952e key\nfor key in hmap.keys():\n    print(key)\n# \u5355\u72ec\u904d\u5386\u503c value\nfor value in hmap.values():\n    print(value)\n
    hash_map.cpp
    /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 key->value\nfor (auto kv: map) {\n    cout << 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++) {\n    cout << 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()) {\n    System.out.println(kv.getKey() + \" -> \" + kv.getValue());\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor (int key: map.keySet()) {\n    System.out.println(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor (String val: map.values()) {\n    System.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) {\n    Console.WriteLine(kv.Key + \" -> \" + kv.Value);\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nforeach (int key in map.Keys) {\n    Console.WriteLine(key);\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nforeach (string val in map.Values) {\n    Console.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 {\n    fmt.Println(key, \"->\", value)\n}\n// \u5355\u72ec\u904d\u5386\u952e key\nfor key := range hmap {\n    fmt.Println(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c value\nfor _, value := range hmap {\n    fmt.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 {\n    print(\"\\(key) -> \\(value)\")\n}\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys {\n    print(key)\n}\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values {\n    print(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()) {\n    console.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\n    console.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\n    console.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()) {\n    console.info(k + ' -> ' + v);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u952e Key');\nfor (const k of map.keys()) {\n    console.info(k);\n}\nconsole.info('\\n\u5355\u72ec\u904d\u5386\u503c Value');\nfor (const v of map.values()) {\n    console.info(v);\n}\n
    hash_map.dart
    /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nmap.forEach((key, value) {\n  print('$key -> $value');\n});\n\n// \u5355\u72ec\u904d\u5386\u952e Key\nmap.keys.forEach((key) {\n  print(key);\n});\n\n// \u5355\u72ec\u904d\u5386\u503c Value\nmap.values.forEach((value) {\n  print(value);\n});\n
    hash_map.rs
    /* \u904d\u5386\u54c8\u5e0c\u8868 */\n// \u904d\u5386\u952e\u503c\u5bf9 Key->Value\nfor (key, value) in &map {\n    println!(\"{key} -> {value}\");\n}\n\n// \u5355\u72ec\u904d\u5386\u952e Key\nfor key in map.keys() {\n    println!(\"{key}\"); \n}\n\n// \u5355\u72ec\u904d\u5386\u503c Value\nfor value in map.values() {\n    println!(\"{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\"\"\"\n\n    def __init__(self, key: int, val: str):\n        self.key = key\n        self.val = val\n\nclass ArrayHashMap:\n    \"\"\"\u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        # \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        self.buckets: list[Pair | None] = [None] * 100\n\n    def hash_func(self, key: int) -> int:\n        \"\"\"\u54c8\u5e0c\u51fd\u6570\"\"\"\n        index = key % 100\n        return index\n\n    def get(self, key: int) -> str:\n        \"\"\"\u67e5\u8be2\u64cd\u4f5c\"\"\"\n        index: int = self.hash_func(key)\n        pair: Pair = self.buckets[index]\n        if pair is None:\n            return None\n        return pair.val\n\n    def put(self, key: int, val: str):\n        \"\"\"\u6dfb\u52a0\u64cd\u4f5c\"\"\"\n        pair = Pair(key, val)\n        index: int = self.hash_func(key)\n        self.buckets[index] = pair\n\n    def remove(self, key: int):\n        \"\"\"\u5220\u9664\u64cd\u4f5c\"\"\"\n        index: int = self.hash_func(key)\n        # \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\n        self.buckets[index] = None\n\n    def entry_set(self) -> list[Pair]:\n        \"\"\"\u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\"\"\"\n        result: list[Pair] = []\n        for pair in self.buckets:\n            if pair is not None:\n                result.append(pair)\n        return result\n\n    def key_set(self) -> list[int]:\n        \"\"\"\u83b7\u53d6\u6240\u6709\u952e\"\"\"\n        result = []\n        for pair in self.buckets:\n            if pair is not None:\n                result.append(pair.key)\n        return result\n\n    def value_set(self) -> list[str]:\n        \"\"\"\u83b7\u53d6\u6240\u6709\u503c\"\"\"\n        result = []\n        for pair in self.buckets:\n            if pair is not None:\n                result.append(pair.val)\n        return result\n\n    def print(self):\n        \"\"\"\u6253\u5370\u54c8\u5e0c\u8868\"\"\"\n        for pair in self.buckets:\n            if pair is not None:\n                print(pair.key, \"->\", pair.val)\n
    array_hash_map.cpp
    /* \u952e\u503c\u5bf9 */\nstruct Pair {\n  public:\n    int key;\n    string val;\n    Pair(int key, string val) {\n        this->key = key;\n        this->val = val;\n    }\n};\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n  private:\n    vector<Pair *> buckets;\n\n  public:\n    ArrayHashMap() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        buckets = vector<Pair *>(100);\n    }\n\n    ~ArrayHashMap() {\n        // \u91ca\u653e\u5185\u5b58\n        for (const auto &bucket : buckets) {\n            delete bucket;\n        }\n        buckets.clear();\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int hashFunc(int key) {\n        int index = key % 100;\n        return index;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    string get(int key) {\n        int index = hashFunc(key);\n        Pair *pair = buckets[index];\n        if (pair == nullptr)\n            return \"\";\n        return pair->val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    void put(int key, string val) {\n        Pair *pair = new Pair(key, val);\n        int index = hashFunc(key);\n        buckets[index] = pair;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    void remove(int key) {\n        int index = hashFunc(key);\n        // \u91ca\u653e\u5185\u5b58\u5e76\u7f6e\u4e3a nullptr\n        delete buckets[index];\n        buckets[index] = nullptr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    vector<Pair *> pairSet() {\n        vector<Pair *> pairSet;\n        for (Pair *pair : buckets) {\n            if (pair != nullptr) {\n                pairSet.push_back(pair);\n            }\n        }\n        return pairSet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    vector<int> keySet() {\n        vector<int> keySet;\n        for (Pair *pair : buckets) {\n            if (pair != nullptr) {\n                keySet.push_back(pair->key);\n            }\n        }\n        return keySet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    vector<string> valueSet() {\n        vector<string> valueSet;\n        for (Pair *pair : buckets) {\n            if (pair != nullptr) {\n                valueSet.push_back(pair->val);\n            }\n        }\n        return valueSet;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    void print() {\n        for (Pair *kv : pairSet()) {\n            cout << kv->key << \" -> \" << kv->val << endl;\n        }\n    }\n};\n
    array_hash_map.java
    /* \u952e\u503c\u5bf9 */\nclass Pair {\n    public int key;\n    public String val;\n\n    public Pair(int key, String val) {\n        this.key = key;\n        this.val = val;\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    private List<Pair> buckets;\n\n    public ArrayHashMap() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        buckets = new ArrayList<>();\n        for (int i = 0; i < 100; i++) {\n            buckets.add(null);\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private int hashFunc(int key) {\n        int index = key % 100;\n        return index;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public String get(int key) {\n        int index = hashFunc(key);\n        Pair pair = buckets.get(index);\n        if (pair == null)\n            return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void put(int key, String val) {\n        Pair pair = new Pair(key, val);\n        int index = hashFunc(key);\n        buckets.set(index, pair);\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void remove(int key) {\n        int index = hashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        buckets.set(index, null);\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    public List<Pair> pairSet() {\n        List<Pair> pairSet = new ArrayList<>();\n        for (Pair pair : buckets) {\n            if (pair != null)\n                pairSet.add(pair);\n        }\n        return pairSet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    public List<Integer> keySet() {\n        List<Integer> keySet = new ArrayList<>();\n        for (Pair pair : buckets) {\n            if (pair != null)\n                keySet.add(pair.key);\n        }\n        return keySet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    public List<String> valueSet() {\n        List<String> valueSet = new ArrayList<>();\n        for (Pair pair : buckets) {\n            if (pair != null)\n                valueSet.add(pair.val);\n        }\n        return valueSet;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void print() {\n        for (Pair kv : pairSet()) {\n            System.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) {\n    public int key = key;\n    public string val = val;\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    List<Pair?> buckets;\n    public ArrayHashMap() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        buckets = [];\n        for (int i = 0; i < 100; i++) {\n            buckets.Add(null);\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    int HashFunc(int key) {\n        int index = key % 100;\n        return index;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public string? Get(int key) {\n        int index = HashFunc(key);\n        Pair? pair = buckets[index];\n        if (pair == null) return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public void Put(int key, string val) {\n        Pair pair = new(key, val);\n        int index = HashFunc(key);\n        buckets[index] = pair;\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public void Remove(int key) {\n        int index = HashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        buckets[index] = null;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    public List<Pair> PairSet() {\n        List<Pair> pairSet = [];\n        foreach (Pair? pair in buckets) {\n            if (pair != null)\n                pairSet.Add(pair);\n        }\n        return pairSet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    public List<int> KeySet() {\n        List<int> keySet = [];\n        foreach (Pair? pair in buckets) {\n            if (pair != null)\n                keySet.Add(pair.key);\n        }\n        return keySet;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    public List<string> ValueSet() {\n        List<string> valueSet = [];\n        foreach (Pair? pair in buckets) {\n            if (pair != null)\n                valueSet.Add(pair.val);\n        }\n        return valueSet;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public void Print() {\n        foreach (Pair kv in PairSet()) {\n            Console.WriteLine(kv.key + \" -> \" + kv.val);\n        }\n    }\n}\n
    array_hash_map.go
    /* \u952e\u503c\u5bf9 */\ntype pair struct {\n    key int\n    val string\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntype arrayHashMap struct {\n    buckets []*pair\n}\n\n/* \u521d\u59cb\u5316\u54c8\u5e0c\u8868 */\nfunc newArrayHashMap() *arrayHashMap {\n    // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n    buckets := make([]*pair, 100)\n    return &arrayHashMap{buckets: buckets}\n}\n\n/* \u54c8\u5e0c\u51fd\u6570 */\nfunc (a *arrayHashMap) hashFunc(key int) int {\n    index := key % 100\n    return index\n}\n\n/* \u67e5\u8be2\u64cd\u4f5c */\nfunc (a *arrayHashMap) get(key int) string {\n    index := a.hashFunc(key)\n    pair := a.buckets[index]\n    if pair == nil {\n        return \"Not Found\"\n    }\n    return pair.val\n}\n\n/* \u6dfb\u52a0\u64cd\u4f5c */\nfunc (a *arrayHashMap) put(key int, val string) {\n    pair := &pair{key: key, val: val}\n    index := a.hashFunc(key)\n    a.buckets[index] = pair\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nfunc (a *arrayHashMap) remove(key int) {\n    index := a.hashFunc(key)\n    // \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\n    a.buckets[index] = nil\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e\u5bf9 */\nfunc (a *arrayHashMap) pairSet() []*pair {\n    var pairs []*pair\n    for _, pair := range a.buckets {\n        if pair != nil {\n            pairs = append(pairs, pair)\n        }\n    }\n    return pairs\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e */\nfunc (a *arrayHashMap) keySet() []int {\n    var keys []int\n    for _, pair := range a.buckets {\n        if pair != nil {\n            keys = append(keys, pair.key)\n        }\n    }\n    return keys\n}\n\n/* \u83b7\u53d6\u6240\u6709\u503c */\nfunc (a *arrayHashMap) valueSet() []string {\n    var values []string\n    for _, pair := range a.buckets {\n        if pair != nil {\n            values = append(values, pair.val)\n        }\n    }\n    return values\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nfunc (a *arrayHashMap) print() {\n    for _, pair := range a.buckets {\n        if pair != nil {\n            fmt.Println(pair.key, \"->\", pair.val)\n        }\n    }\n}\n
    array_hash_map.swift
    /* \u952e\u503c\u5bf9 */\nclass Pair: Equatable {\n    public var key: Int\n    public var val: String\n\n    public init(key: Int, val: String) {\n        self.key = key\n        self.val = val\n    }\n\n    public static func == (lhs: Pair, rhs: Pair) -> Bool {\n        lhs.key == rhs.key && lhs.val == rhs.val\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    private var buckets: [Pair?] = []\n\n    init() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        for _ in 0 ..< 100 {\n            buckets.append(nil)\n        }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private func hashFunc(key: Int) -> Int {\n        let index = key % 100\n        return index\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    func get(key: Int) -> String? {\n        let index = hashFunc(key: key)\n        let pair = buckets[index]\n        return pair?.val\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    func put(key: Int, val: String) {\n        let pair = Pair(key: key, val: val)\n        let index = hashFunc(key: key)\n        buckets[index] = pair\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    func remove(key: Int) {\n        let index = hashFunc(key: key)\n        // \u7f6e\u4e3a nil \uff0c\u4ee3\u8868\u5220\u9664\n        buckets[index] = nil\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    func pairSet() -> [Pair] {\n        var pairSet: [Pair] = []\n        for pair in buckets {\n            if let pair = pair {\n                pairSet.append(pair)\n            }\n        }\n        return pairSet\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    func keySet() -> [Int] {\n        var keySet: [Int] = []\n        for pair in buckets {\n            if let pair = pair {\n                keySet.append(pair.key)\n            }\n        }\n        return keySet\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    func valueSet() -> [String] {\n        var valueSet: [String] = []\n        for pair in buckets {\n            if let pair = pair {\n                valueSet.append(pair.val)\n            }\n        }\n        return valueSet\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    func print() {\n        for pair in pairSet() {\n            Swift.print(\"\\(pair.key) -> \\(pair.val)\")\n        }\n    }\n}\n
    array_hash_map.js
    /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\n    constructor(key, val) {\n        this.key = key;\n        this.val = val;\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    #buckets;\n    constructor() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        this.#buckets = new Array(100).fill(null);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    #hashFunc(key) {\n        return key % 100;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    get(key) {\n        let index = this.#hashFunc(key);\n        let pair = this.#buckets[index];\n        if (pair === null) return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    set(key, val) {\n        let index = this.#hashFunc(key);\n        this.#buckets[index] = new Pair(key, val);\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    delete(key) {\n        let index = this.#hashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        this.#buckets[index] = null;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    entries() {\n        let arr = [];\n        for (let i = 0; i < this.#buckets.length; i++) {\n            if (this.#buckets[i]) {\n                arr.push(this.#buckets[i]);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    keys() {\n        let arr = [];\n        for (let i = 0; i < this.#buckets.length; i++) {\n            if (this.#buckets[i]) {\n                arr.push(this.#buckets[i].key);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    values() {\n        let arr = [];\n        for (let i = 0; i < this.#buckets.length; i++) {\n            if (this.#buckets[i]) {\n                arr.push(this.#buckets[i].val);\n            }\n        }\n        return arr;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    print() {\n        let pairSet = this.entries();\n        for (const pair of pairSet) {\n            console.info(`${pair.key} -> ${pair.val}`);\n        }\n    }\n}\n
    array_hash_map.ts
    /* \u952e\u503c\u5bf9 Number -> String */\nclass Pair {\n    public key: number;\n    public val: string;\n\n    constructor(key: number, val: string) {\n        this.key = key;\n        this.val = val;\n    }\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n    private readonly buckets: (Pair | null)[];\n\n    constructor() {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        this.buckets = new Array(100).fill(null);\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    private hashFunc(key: number): number {\n        return key % 100;\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    public get(key: number): string | null {\n        let index = this.hashFunc(key);\n        let pair = this.buckets[index];\n        if (pair === null) return null;\n        return pair.val;\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    public set(key: number, val: string) {\n        let index = this.hashFunc(key);\n        this.buckets[index] = new Pair(key, val);\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    public delete(key: number) {\n        let index = this.hashFunc(key);\n        // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n        this.buckets[index] = null;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    public entries(): (Pair | null)[] {\n        let arr: (Pair | null)[] = [];\n        for (let i = 0; i < this.buckets.length; i++) {\n            if (this.buckets[i]) {\n                arr.push(this.buckets[i]);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    public keys(): (number | undefined)[] {\n        let arr: (number | undefined)[] = [];\n        for (let i = 0; i < this.buckets.length; i++) {\n            if (this.buckets[i]) {\n                arr.push(this.buckets[i].key);\n            }\n        }\n        return arr;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    public values(): (string | undefined)[] {\n        let arr: (string | undefined)[] = [];\n        for (let i = 0; i < this.buckets.length; i++) {\n            if (this.buckets[i]) {\n                arr.push(this.buckets[i].val);\n            }\n        }\n        return arr;\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    public print() {\n        let pairSet = this.entries();\n        for (const pair of pairSet) {\n            console.info(`${pair.key} -> ${pair.val}`);\n        }\n    }\n}\n
    array_hash_map.dart
    /* \u952e\u503c\u5bf9 */\nclass Pair {\n  int key;\n  String val;\n  Pair(this.key, this.val);\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\nclass ArrayHashMap {\n  late List<Pair?> _buckets;\n\n  ArrayHashMap() {\n    // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n    _buckets = List.filled(100, null);\n  }\n\n  /* \u54c8\u5e0c\u51fd\u6570 */\n  int _hashFunc(int key) {\n    final int index = key % 100;\n    return index;\n  }\n\n  /* \u67e5\u8be2\u64cd\u4f5c */\n  String? get(int key) {\n    final int index = _hashFunc(key);\n    final Pair? pair = _buckets[index];\n    if (pair == null) {\n      return null;\n    }\n    return pair.val;\n  }\n\n  /* \u6dfb\u52a0\u64cd\u4f5c */\n  void put(int key, String val) {\n    final Pair pair = Pair(key, val);\n    final int index = _hashFunc(key);\n    _buckets[index] = pair;\n  }\n\n  /* \u5220\u9664\u64cd\u4f5c */\n  void remove(int key) {\n    final int index = _hashFunc(key);\n    _buckets[index] = null;\n  }\n\n  /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n  List<Pair> pairSet() {\n    List<Pair> pairSet = [];\n    for (final Pair? pair in _buckets) {\n      if (pair != null) {\n        pairSet.add(pair);\n      }\n    }\n    return pairSet;\n  }\n\n  /* \u83b7\u53d6\u6240\u6709\u952e */\n  List<int> keySet() {\n    List<int> keySet = [];\n    for (final Pair? pair in _buckets) {\n      if (pair != null) {\n        keySet.add(pair.key);\n      }\n    }\n    return keySet;\n  }\n\n  /* \u83b7\u53d6\u6240\u6709\u503c */\n  List<String> values() {\n    List<String> valueSet = [];\n    for (final Pair? pair in _buckets) {\n      if (pair != null) {\n        valueSet.add(pair.val);\n      }\n    }\n    return valueSet;\n  }\n\n  /* \u6253\u5370\u54c8\u5e0c\u8868 */\n  void printHashMap() {\n    for (final Pair kv in pairSet()) {\n      print(\"${kv.key} -> ${kv.val}\");\n    }\n  }\n}\n
    array_hash_map.rs
    /* \u952e\u503c\u5bf9 */\n#[derive(Debug, Clone, PartialEq)]\npub struct Pair {\n    pub key: i32,\n    pub val: String,\n}\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\npub struct ArrayHashMap {\n    buckets: Vec<Option<Pair>>\n}\n\nimpl ArrayHashMap {\n    pub fn new() -> ArrayHashMap {\n        // \u521d\u59cb\u5316\u6570\u7ec4\uff0c\u5305\u542b 100 \u4e2a\u6876\n        Self { buckets: vec![None; 100] }\n    }\n\n    /* \u54c8\u5e0c\u51fd\u6570 */\n    fn hash_func(&self, key: i32) -> usize {\n        key as usize % 100\n    }\n\n    /* \u67e5\u8be2\u64cd\u4f5c */\n    pub fn get(&self, key: i32) -> Option<&String> {\n        let index = self.hash_func(key);\n        self.buckets[index].as_ref().map(|pair| &pair.val)\n    }\n\n    /* \u6dfb\u52a0\u64cd\u4f5c */\n    pub fn put(&mut self, key: i32, val: &str) {\n        let index = self.hash_func(key);\n        self.buckets[index] = Some(Pair {\n            key,\n            val: val.to_string(),\n        });\n    }\n\n    /* \u5220\u9664\u64cd\u4f5c */\n    pub fn remove(&mut self, key: i32) {\n        let index = self.hash_func(key);\n        // \u7f6e\u4e3a None \uff0c\u4ee3\u8868\u5220\u9664\n        self.buckets[index] = None;\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\n    pub fn entry_set(&self) -> Vec<&Pair> {\n        self.buckets.iter().filter_map(|pair| pair.as_ref()).collect()\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u952e */\n    pub fn key_set(&self) -> Vec<&i32> {\n        self.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.key)).collect()\n    }\n\n    /* \u83b7\u53d6\u6240\u6709\u503c */\n    pub fn value_set(&self) -> Vec<&String> {\n        self.buckets.iter().filter_map(|pair| pair.as_ref().map(|pair| &pair.val)).collect()\n    }\n\n    /* \u6253\u5370\u54c8\u5e0c\u8868 */\n    pub fn print(&self) {\n        for pair in self.entry_set() {\n            println!(\"{} -> {}\", pair.key, pair.val);\n        }\n    }\n}\n
    array_hash_map.c
    /* \u952e\u503c\u5bf9 int->string */\ntypedef struct {\n    int key;\n    char *val;\n} Pair;\n\n/* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868 */\ntypedef struct {\n    Pair *buckets[HASHTABLE_CAPACITY];\n} ArrayHashMap;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayHashMap *newArrayHashMap() {\n    ArrayHashMap *hmap = malloc(sizeof(ArrayHashMap));\n    return hmap;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayHashMap(ArrayHashMap *hmap) {\n    for (int i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            free(hmap->buckets[i]->val);\n            free(hmap->buckets[i]);\n        }\n    }\n    free(hmap);\n}\n\n/* \u6dfb\u52a0\u64cd\u4f5c */\nvoid put(ArrayHashMap *hmap, const int key, const char *val) {\n    Pair *Pair = malloc(sizeof(Pair));\n    Pair->key = key;\n    Pair->val = malloc(strlen(val) + 1);\n    strcpy(Pair->val, val);\n\n    int index = hashFunc(key);\n    hmap->buckets[index] = Pair;\n}\n\n/* \u5220\u9664\u64cd\u4f5c */\nvoid removeItem(ArrayHashMap *hmap, const int key) {\n    int index = hashFunc(key);\n    free(hmap->buckets[index]->val);\n    free(hmap->buckets[index]);\n    hmap->buckets[index] = NULL;\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9 */\nvoid pairSet(ArrayHashMap *hmap, MapSet *set) {\n    Pair *entries;\n    int i = 0, index = 0;\n    int total = 0;\n    /* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            total++;\n        }\n    }\n    entries = malloc(sizeof(Pair) * total);\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            entries[index].key = hmap->buckets[i]->key;\n            entries[index].val = malloc(strlen(hmap->buckets[i]->val) + 1);\n            strcpy(entries[index].val, hmap->buckets[i]->val);\n            index++;\n        }\n    }\n    set->set = entries;\n    set->len = total;\n}\n\n/* \u83b7\u53d6\u6240\u6709\u952e */\nvoid keySet(ArrayHashMap *hmap, MapSet *set) {\n    int *keys;\n    int i = 0, index = 0;\n    int total = 0;\n    /* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            total++;\n        }\n    }\n    keys = malloc(total * sizeof(int));\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            keys[index] = hmap->buckets[i]->key;\n            index++;\n        }\n    }\n    set->set = keys;\n    set->len = total;\n}\n\n/* \u83b7\u53d6\u6240\u6709\u503c */\nvoid valueSet(ArrayHashMap *hmap, MapSet *set) {\n    char **vals;\n    int i = 0, index = 0;\n    int total = 0;\n    /* \u7edf\u8ba1\u6709\u6548\u952e\u503c\u5bf9\u6570\u91cf */\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            total++;\n        }\n    }\n    vals = malloc(total * sizeof(char *));\n    for (i = 0; i < HASHTABLE_CAPACITY; i++) {\n        if (hmap->buckets[i] != NULL) {\n            vals[index] = hmap->buckets[i]->val;\n            index++;\n        }\n    }\n    set->set = vals;\n    set->len = total;\n}\n\n/* \u6253\u5370\u54c8\u5e0c\u8868 */\nvoid print(ArrayHashMap *hmap) {\n    int i;\n    MapSet set;\n    pairSet(hmap, &set);\n    Pair *entries = (Pair *)set.set;\n    for (i = 0; i < set.len; i++) {\n        printf(\"%d -> %s\\n\", entries[i].key, entries[i].val);\n    }\n    free(set.set);\n}\n
    array_hash_map.zig
    // \u952e\u503c\u5bf9\nconst Pair = struct {\n    key: usize = undefined,\n    val: []const u8 = undefined,\n\n   pub fn init(key: usize, val: []const u8) Pair {\n        return Pair {\n            .key = key,\n            .val = val,\n        };\n    }\n};\n\n// \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u54c8\u5e0c\u8868\nfn ArrayHashMap(comptime T: type) type {\n    return struct {\n        bucket: ?std.ArrayList(?T) = null,\n        mem_allocator: std.mem.Allocator = undefined,\n\n        const Self = @This();\n\n        // \u6784\u9020\u51fd\u6570\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            self.mem_allocator = allocator;\n            // \u521d\u59cb\u5316\u4e00\u4e2a\u957f\u5ea6\u4e3a 100 \u7684\u6876\uff08\u6570\u7ec4\uff09\n            self.bucket = std.ArrayList(?T).init(self.mem_allocator);\n            var i: i32 = 0;\n            while (i < 100) : (i += 1) {\n                try self.bucket.?.append(null);\n            }\n        }\n\n        // \u6790\u6784\u51fd\u6570\n        pub fn deinit(self: *Self) void {\n            if (self.bucket != null) self.bucket.?.deinit();\n        }\n\n        // \u54c8\u5e0c\u51fd\u6570\n        fn hashFunc(key: usize) usize {\n            var index = key % 100;\n            return index;\n        }\n\n        // \u67e5\u8be2\u64cd\u4f5c\n        pub fn get(self: *Self, key: usize) []const u8 {\n            var index = hashFunc(key);\n            var pair = self.bucket.?.items[index];\n            return pair.?.val;\n        }\n\n        // \u6dfb\u52a0\u64cd\u4f5c\n        pub fn put(self: *Self, key: usize, val: []const u8) !void {\n            var pair = Pair.init(key, val);\n            var index = hashFunc(key);\n            self.bucket.?.items[index] = pair;\n        }\n\n        // \u5220\u9664\u64cd\u4f5c\n        pub fn remove(self: *Self, key: usize) !void {\n            var index = hashFunc(key);\n            // \u7f6e\u4e3a null \uff0c\u4ee3\u8868\u5220\u9664\n            self.bucket.?.items[index] = null;\n        }       \n\n        // \u83b7\u53d6\u6240\u6709\u952e\u503c\u5bf9\n        pub fn pairSet(self: *Self) !std.ArrayList(T) {\n            var entry_set = std.ArrayList(T).init(self.mem_allocator);\n            for (self.bucket.?.items) |item| {\n                if (item == null) continue;\n                try entry_set.append(item.?);\n            }\n            return entry_set;\n        }  \n\n        // \u83b7\u53d6\u6240\u6709\u952e\n        pub fn keySet(self: *Self) !std.ArrayList(usize) {\n            var key_set = std.ArrayList(usize).init(self.mem_allocator);\n            for (self.bucket.?.items) |item| {\n                if (item == null) continue;\n                try key_set.append(item.?.key);\n            }\n            return key_set;\n        }  \n\n        // \u83b7\u53d6\u6240\u6709\u503c\n        pub fn valueSet(self: *Self) !std.ArrayList([]const u8) {\n            var value_set = std.ArrayList([]const u8).init(self.mem_allocator);\n            for (self.bucket.?.items) |item| {\n                if (item == null) continue;\n                try value_set.append(item.?.val);\n            }\n            return value_set;\n        }\n\n        // \u6253\u5370\u54c8\u5e0c\u8868\n        pub fn print(self: *Self) !void {\n            var entry_set = try self.pairSet();\n            defer entry_set.deinit();\n            for (entry_set.items) |item| {\n                std.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\u589e\u52a0\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\u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\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\u6a21\uff08\u53d6\u4f59\uff09\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\u5730\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\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\u7531\u4e8e\u53f6\u8282\u70b9\u6ca1\u6709\u5b50\u8282\u70b9\uff0c\u56e0\u6b64\u5b83\u4eec\u5929\u7136\u5c31\u662f\u5408\u6cd5\u7684\u5b50\u5806\uff0c\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\uff1a

    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\n    self.max_heap = nums\n    # \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for i in range(self.parent(self.size() - 1), -1, -1):\n        self.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\n    maxHeap = nums;\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (int i = parent(size() - 1); i >= 0; i--) {\n        siftDown(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\n    maxHeap = new ArrayList<>(nums);\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (int i = parent(size() - 1); i >= 0; i--) {\n        siftDown(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\n    maxHeap = new List<int>(nums);\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    var size = Parent(this.Size() - 1);\n    for (int i = size; i >= 0; i--) {\n        SiftDown(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\n    h := &maxHeap{data: nums}\n    for 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\n        h.siftDown(i)\n    }\n    return 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\n    maxHeap = nums\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for i in stride(from: parent(i: size() - 1), through: 0, by: -1) {\n        siftDown(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\n    this.#maxHeap = nums === undefined ? [] : [...nums];\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (let i = this.#parent(this.size() - 1); i >= 0; i--) {\n        this.#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\n    this.maxHeap = nums === undefined ? [] : [...nums];\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for (let i = this.parent(this.size() - 1); i >= 0; i--) {\n        this.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\n  for (int i = _parent(size() - 1); i >= 0; i--) {\n    siftDown(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\n    let mut heap = MaxHeap { max_heap: nums };\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    for i in (0..=Self::parent(heap.size() - 1)).rev() {\n        heap.sift_down(i);\n    }\n    heap\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\n    MaxHeap *maxHeap = (MaxHeap *)malloc(sizeof(MaxHeap));\n    maxHeap->size = size;\n    memcpy(maxHeap->data, nums, size * sizeof(int));\n    for (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\n        siftDown(maxHeap, i);\n    }\n    return 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 {\n    if (self.max_heap != null) return;\n    self.max_heap = std.ArrayList(T).init(allocator);\n    // \u5c06\u5217\u8868\u5143\u7d20\u539f\u5c01\u4e0d\u52a8\u6dfb\u52a0\u8fdb\u5806\n    try self.max_heap.?.appendSlice(nums);\n    // \u5806\u5316\u9664\u53f6\u8282\u70b9\u4ee5\u5916\u7684\u5176\u4ed6\u6240\u6709\u8282\u70b9\n    var i: usize = parent(self.size() - 1) + 1;\n    while (i > 0) : (i -= 1) {\n        try 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\u5c06\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\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\u5c0f\u9876\u5806 min heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\leq\\) \u5176\u5b50\u8282\u70b9\u7684\u503c\u3002
    • \u300c\u5927\u9876\u5806 max heap\u300d\uff1a\u4efb\u610f\u8282\u70b9\u7684\u503c \\(\\geq\\) \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\u662f\u6700\u5927\uff08\u6700\u5c0f\uff09\u7684\u3002
    "},{"location":"chapter_heap/heap/#811","title":"8.1.1 \u00a0 \u5806\u7684\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\u7684\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\u5bf9\u4e8e\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\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\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\n# \u83b7\u53d6\u5806\u9876\u5143\u7d20\npeek: int = flag * max_heap[0] # 5\n\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\n# \u83b7\u53d6\u5806\u5927\u5c0f\nsize: int = len(max_heap)\n\n# \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = not max_heap\n\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\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.push(1);\nmaxHeap.push(3);\nmaxHeap.push(2);\nmaxHeap.push(5);\nmaxHeap.push(4);\n\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.top(); // 5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.empty();\n\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\n/* \u5143\u7d20\u5165\u5806 */\nmaxHeap.offer(1);\nmaxHeap.offer(3);\nmaxHeap.offer(2);\nmaxHeap.offer(5);\nmaxHeap.offer(4);\n\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.peek(); // 5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.size();\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = maxHeap.isEmpty();\n\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\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\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nint peek = maxHeap.Peek();//5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nint size = maxHeap.Count;\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty = maxHeap.Count == 0;\n\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\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\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\n    last := (*h)[len(*h)-1]\n    *h = (*h)[:len(*h)-1]\n    return last\n}\n\n// Len sort.Interface \u7684\u65b9\u6cd5\nfunc (h *intHeap) Len() int {\n    return len(*h)\n}\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\n    return (*h)[i].(int) > (*h)[j].(int)\n}\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\n// Top \u83b7\u53d6\u5806\u9876\u5143\u7d20\nfunc (h *intHeap) Top() any {\n    return (*h)[0]\n}\n\n/* Driver Code */\nfunc TestHeap(t *testing.T) {\n    /* \u521d\u59cb\u5316\u5806 */\n    // \u521d\u59cb\u5316\u5927\u9876\u5806\n    maxHeap := &intHeap{}\n    heap.Init(maxHeap)\n    /* \u5143\u7d20\u5165\u5806 */\n    // \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u6dfb\u52a0\u5143\u7d20\n    heap.Push(maxHeap, 1)\n    heap.Push(maxHeap, 3)\n    heap.Push(maxHeap, 2)\n    heap.Push(maxHeap, 4)\n    heap.Push(maxHeap, 5)\n\n    /* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\n    top := maxHeap.Top()\n    fmt.Printf(\"\u5806\u9876\u5143\u7d20\u4e3a %d\\n\", top)\n\n    /* \u5806\u9876\u5143\u7d20\u51fa\u5806 */\n    // \u8c03\u7528 heap.Interface \u7684\u65b9\u6cd5\uff0c\u6765\u79fb\u9664\u5143\u7d20\n    heap.Pop(maxHeap) // 5\n    heap.Pop(maxHeap) // 4\n    heap.Pop(maxHeap) // 3\n    heap.Pop(maxHeap) // 2\n    heap.Pop(maxHeap) // 1\n\n    /* \u83b7\u53d6\u5806\u5927\u5c0f */\n    size := len(*maxHeap)\n    fmt.Printf(\"\u5806\u5143\u7d20\u6570\u91cf\u4e3a %d\\n\", size)\n\n    /* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\n    isEmpty := len(*maxHeap) == 0\n    fmt.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\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\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\n/* \u83b7\u53d6\u5806\u9876\u5143\u7d20 */\nlet peek = max_heap.peek().unwrap();  // 5\n\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\n/* \u83b7\u53d6\u5806\u5927\u5c0f */\nlet size = max_heap.len();\n\n/* \u5224\u65ad\u5806\u662f\u5426\u4e3a\u7a7a */\nlet is_empty = max_heap.is_empty();\n\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\u7684\u7d22\u5f15\u4e3a \\(2i + 1\\) \uff0c\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\u4e3a \\(2i + 2\\) \uff0c\u7236\u8282\u70b9\u7684\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\u7684\u7d22\u5f15\"\"\"\n    return 2 * i + 1\n\ndef right(self, i: int) -> int:\n    \"\"\"\u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n    return 2 * i + 2\n\ndef parent(self, i: int) -> int:\n    \"\"\"\u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n    return (i - 1) // 2  # \u5411\u4e0b\u6574\u9664\n
    my_heap.cpp
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint left(int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(int i) {\n    return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.java
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint left(int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(int i) {\n    return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.cs
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint Left(int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint Right(int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint Parent(int i) {\n    return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.go
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (h *maxHeap) left(i int) int {\n    return 2*i + 1\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (h *maxHeap) right(i int) int {\n    return 2*i + 2\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (h *maxHeap) parent(i int) int {\n    // \u5411\u4e0b\u6574\u9664\n    return (i - 1) / 2\n}\n
    my_heap.swift
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc left(i: Int) -> Int {\n    2 * i + 1\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc right(i: Int) -> Int {\n    2 * i + 2\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\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\u7684\u7d22\u5f15 */\n#left(i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n#right(i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n#parent(i) {\n    return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.ts
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nleft(i: number): number {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nright(i: number): number {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nparent(i: number): number {\n    return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.dart
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint _left(int i) {\n  return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint _right(int i) {\n  return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint _parent(int i) {\n  return (i - 1) ~/ 2; // \u5411\u4e0b\u6574\u9664\n}\n
    my_heap.rs
    /* \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn left(i: usize) -> usize {\n    2 * i + 1\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nfn right(i: usize) -> usize {\n    2 * i + 2\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\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\u7684\u7d22\u5f15 */\nint left(MaxHeap *maxHeap, int i) {\n    return 2 * i + 1;\n}\n\n/* \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\nint right(MaxHeap *maxHeap, int i) {\n    return 2 * i + 2;\n}\n\n/* \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nint parent(MaxHeap *maxHeap, int i) {\n    return (i - 1) / 2;\n}\n
    my_heap.zig
    // \u83b7\u53d6\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15\nfn left(i: usize) usize {\n    return 2 * i + 1;\n}\n\n// \u83b7\u53d6\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\nfn right(i: usize) usize {\n    return 2 * i + 2;\n}\n\n// \u83b7\u53d6\u7236\u8282\u70b9\u7684\u7d22\u5f15\nfn parent(i: usize) usize {\n    // return (i - 1) / 2; // \u5411\u4e0b\u6574\u9664\n    return @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\"\"\"\n    return self.max_heap[0]\n
    my_heap.cpp
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\n    return maxHeap[0];\n}\n
    my_heap.java
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\n    return maxHeap.get(0);\n}\n
    my_heap.cs
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint Peek() {\n    return maxHeap[0];\n}\n
    my_heap.go
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc (h *maxHeap) peek() any {\n    return h.data[0]\n}\n
    my_heap.swift
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunc peek() -> Int {\n    maxHeap[0]\n}\n
    my_heap.js
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek() {\n    return this.#maxHeap[0];\n}\n
    my_heap.ts
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\npeek(): number {\n    return this.maxHeap[0];\n}\n
    my_heap.dart
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek() {\n  return _maxHeap[0];\n}\n
    my_heap.rs
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfn peek(&self) -> Option<i32> {\n    self.max_heap.first().copied()\n}\n
    my_heap.c
    /* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peek(MaxHeap *maxHeap) {\n    return maxHeap->data[0];\n}\n
    my_heap.zig
    // \u8bbf\u95ee\u5806\u9876\u5143\u7d20\nfn peek(self: *Self) T {\n    return self.max_heap.?.items[0];\n}  \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\n    self.max_heap.append(val)\n    # \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    self.sift_up(self.size() - 1)\n\ndef sift_up(self, i: int):\n    \"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\"\"\"\n    while True:\n        # \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        p = 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\n        if p < 0 or self.max_heap[i] <= self.max_heap[p]:\n            break\n        # \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, p)\n        # \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p\n
    my_heap.cpp
    /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.push_back(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap[i] <= maxHeap[p])\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(maxHeap[i], maxHeap[p]);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.java
    /* \u5143\u7d20\u5165\u5806 */\nvoid push(int val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.add(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap.get(i) <= maxHeap.get(p))\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.cs
    /* \u5143\u7d20\u5165\u5806 */\nvoid Push(int val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.Add(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    SiftUp(Size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid SiftUp(int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap[i] <= maxHeap[p])\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        Swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.go
    /* \u5143\u7d20\u5165\u5806 */\nfunc (h *maxHeap) push(val any) {\n    // \u6dfb\u52a0\u8282\u70b9\n    h.data = append(h.data, val)\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    h.siftUp(len(h.data) - 1)\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc (h *maxHeap) siftUp(i int) {\n    for true {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        p := 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\n        if p < 0 || h.data[i].(int) <= h.data[p].(int) {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        h.swap(i, p)\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p\n    }\n}\n
    my_heap.swift
    /* \u5143\u7d20\u5165\u5806 */\nfunc push(val: Int) {\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap.append(val)\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(i: size() - 1)\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfunc siftUp(i: Int) {\n    var i = i\n    while true {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        let 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\n        if p < 0 || maxHeap[i] <= maxHeap[p] {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i: i, j: p)\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p\n    }\n}\n
    my_heap.js
    /* \u5143\u7d20\u5165\u5806 */\npush(val) {\n    // \u6dfb\u52a0\u8282\u70b9\n    this.#maxHeap.push(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    this.#siftUp(this.size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\n#siftUp(i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        const 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\n        if (p < 0 || this.#maxHeap[i] <= this.#maxHeap[p]) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.#swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.ts
    /* \u5143\u7d20\u5165\u5806 */\npush(val: number): void {\n    // \u6dfb\u52a0\u8282\u70b9\n    this.maxHeap.push(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    this.siftUp(this.size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nsiftUp(i: number): void {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        const 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\n        if (p < 0 || this.maxHeap[i] <= this.maxHeap[p]) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = 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\n  siftUp(size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(int i) {\n  while (true) {\n    // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n    int 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\n    if (p < 0 || _maxHeap[i] <= _maxHeap[p]) {\n      break;\n    }\n    // \u4ea4\u6362\u4e24\u8282\u70b9\n    _swap(i, p);\n    // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n    i = p;\n  }\n}\n
    my_heap.rs
    /* \u5143\u7d20\u5165\u5806 */\nfn push(&mut self, val: i32) {\n    // \u6dfb\u52a0\u8282\u70b9\n    self.max_heap.push(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    self.sift_up(self.size() - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nfn sift_up(&mut self, mut i: usize) {\n    loop {\n        // \u8282\u70b9 i \u5df2\u7ecf\u662f\u5806\u9876\u8282\u70b9\u4e86\uff0c\u7ed3\u675f\u5806\u5316\n        if i == 0 {\n            break;\n        }\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        let p = Self::parent(i);\n        // \u5f53\u201c\u8282\u70b9\u65e0\u987b\u4fee\u590d\u201d\u65f6\uff0c\u7ed3\u675f\u5806\u5316\n        if self.max_heap[i] <= self.max_heap[p] {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = 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\n    if (maxHeap->size == MAX_SIZE) {\n        printf(\"heap is full!\");\n        return;\n    }\n    // \u6dfb\u52a0\u8282\u70b9\n    maxHeap->data[maxHeap->size] = val;\n    maxHeap->size++;\n\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    siftUp(maxHeap, maxHeap->size - 1);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316 */\nvoid siftUp(MaxHeap *maxHeap, int i) {\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        int 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\n        if (p < 0 || maxHeap->data[i] <= maxHeap->data[p]) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(maxHeap, i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = p;\n    }\n}\n
    my_heap.zig
    // \u5143\u7d20\u5165\u5806\nfn push(self: *Self, val: T) !void {\n    // \u6dfb\u52a0\u8282\u70b9\n    try self.max_heap.?.append(val);\n    // \u4ece\u5e95\u81f3\u9876\u5806\u5316\n    try self.siftUp(self.size() - 1);\n}  \n\n// \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u5e95\u81f3\u9876\u5806\u5316\nfn siftUp(self: *Self, i_: usize) !void {\n    var i = i_;\n    while (true) {\n        // \u83b7\u53d6\u8282\u70b9 i \u7684\u7236\u8282\u70b9\n        var 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\n        if (p < 0 or self.max_heap.?.items[i] <= self.max_heap.?.items[p]) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        try self.swap(i, p);\n        // \u5faa\u73af\u5411\u4e0a\u5806\u5316\n        i = 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\n    if self.is_empty():\n        raise 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\n    self.swap(0, self.size() - 1)\n    # \u5220\u9664\u8282\u70b9\n    val = self.max_heap.pop()\n    # \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    self.sift_down(0)\n    # \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val\n\ndef sift_down(self, i: int):\n    \"\"\"\u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\"\"\"\n    while True:\n        # \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        l, r, ma = self.left(i), self.right(i), i\n        if l < self.size() and self.max_heap[l] > self.max_heap[ma]:\n            ma = l\n        if r < self.size() and self.max_heap[r] > self.max_heap[ma]:\n            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\n        if ma == i:\n            break\n        # \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, ma)\n        # \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n
    my_heap.cpp
    /* \u5143\u7d20\u51fa\u5806 */\nvoid pop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (isEmpty()) {\n        throw 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\n    swap(maxHeap[0], maxHeap[size() - 1]);\n    // \u5220\u9664\u8282\u70b9\n    maxHeap.pop_back();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(0);\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = left(i), r = right(i), ma = i;\n        if (l < size() && maxHeap[l] > maxHeap[ma])\n            ma = l;\n        if (r < size() && maxHeap[r] > maxHeap[ma])\n            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\n        if (ma == i)\n            break;\n        swap(maxHeap[i], maxHeap[ma]);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.java
    /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (isEmpty())\n        throw 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\n    swap(0, size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    int val = maxHeap.remove(size() - 1);\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = left(i), r = right(i), ma = i;\n        if (l < size() && maxHeap.get(l) > maxHeap.get(ma))\n            ma = l;\n        if (r < size() && maxHeap.get(r) > maxHeap.get(ma))\n            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\n        if (ma == i)\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.cs
    /* \u5143\u7d20\u51fa\u5806 */\nint Pop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (IsEmpty())\n        throw 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\n    Swap(0, Size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    int val = maxHeap.Last();\n    maxHeap.RemoveAt(Size() - 1);\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    SiftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid SiftDown(int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = Left(i), r = Right(i), ma = i;\n        if (l < Size() && maxHeap[l] > maxHeap[ma])\n            ma = l;\n        if (r < Size() && maxHeap[r] > maxHeap[ma])\n            ma = r;\n        // \u82e5\u201c\u8282\u70b9 i \u6700\u5927\u201d\u6216\u201c\u8d8a\u8fc7\u53f6\u8282\u70b9\u201d\uff0c\u5219\u7ed3\u675f\u5806\u5316\n        if (ma == i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        Swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.go
    /* \u5143\u7d20\u51fa\u5806 */\nfunc (h *maxHeap) pop() any {\n    // \u5224\u7a7a\u5904\u7406\n    if h.isEmpty() {\n        fmt.Println(\"error\")\n        return 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\n    h.swap(0, h.size()-1)\n    // \u5220\u9664\u8282\u70b9\n    val := h.data[len(h.data)-1]\n    h.data = h.data[:len(h.data)-1]\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    h.siftDown(0)\n\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc (h *maxHeap) siftDown(i int) {\n    for true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\n        l, r, max := h.left(i), h.right(i), i\n        if l < h.size() && h.data[l].(int) > h.data[max].(int) {\n            max = l\n        }\n        if r < h.size() && h.data[r].(int) > h.data[max].(int) {\n            max = 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\n        if max == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        h.swap(i, max)\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = max\n    }\n}\n
    my_heap.swift
    /* \u5143\u7d20\u51fa\u5806 */\nfunc pop() -> Int {\n    // \u5224\u7a7a\u5904\u7406\n    if isEmpty() {\n        fatalError(\"\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\n    swap(i: 0, j: size() - 1)\n    // \u5220\u9664\u8282\u70b9\n    let val = maxHeap.remove(at: size() - 1)\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(i: 0)\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfunc siftDown(i: Int) {\n    var i = i\n    while true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = left(i: i)\n        let r = right(i: i)\n        var ma = i\n        if l < size(), maxHeap[l] > maxHeap[ma] {\n            ma = l\n        }\n        if r < size(), maxHeap[r] > maxHeap[ma] {\n            ma = 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\n        if ma == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(i: i, j: ma)\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n    }\n}\n
    my_heap.js
    /* \u5143\u7d20\u51fa\u5806 */\npop() {\n    // \u5224\u7a7a\u5904\u7406\n    if (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\n    this.#swap(0, this.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    const val = this.#maxHeap.pop();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    this.#siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\n#siftDown(i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        const l = this.#left(i),\n            r = this.#right(i);\n        let ma = i;\n        if (l < this.size() && this.#maxHeap[l] > this.#maxHeap[ma]) ma = l;\n        if (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\n        if (ma === i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.#swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.ts
    /* \u5143\u7d20\u51fa\u5806 */\npop(): number {\n    // \u5224\u7a7a\u5904\u7406\n    if (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\n    this.swap(0, this.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    const val = this.maxHeap.pop();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    this.siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nsiftDown(i: number): void {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        const l = this.left(i),\n            r = this.right(i);\n        let ma = i;\n        if (l < this.size() && this.maxHeap[l] > this.maxHeap[ma]) ma = l;\n        if (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\n        if (ma === i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        this.swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.dart
    /* \u5143\u7d20\u51fa\u5806 */\nint pop() {\n  // \u5224\u7a7a\u5904\u7406\n  if (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\n  int val = _maxHeap.removeLast();\n  // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n  siftDown(0);\n  // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n  return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(int i) {\n  while (true) {\n    // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n    int l = _left(i);\n    int r = _right(i);\n    int ma = i;\n    if (l < size() && _maxHeap[l] > _maxHeap[ma]) ma = l;\n    if (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\n    if (ma == i) break;\n    // \u4ea4\u6362\u4e24\u8282\u70b9\n    _swap(i, ma);\n    // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n    i = ma;\n  }\n}\n
    my_heap.rs
    /* \u5143\u7d20\u51fa\u5806 */\nfn pop(&mut self) -> i32 {\n    // \u5224\u7a7a\u5904\u7406\n    if self.is_empty() {\n        panic!(\"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\n    self.swap(0, self.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    let val = self.max_heap.remove(self.size() - 1);\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    self.sift_down(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    val\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nfn sift_down(&mut self, mut i: usize) {\n    loop {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let (l, r, mut ma) = (Self::left(i), Self::right(i), i);\n        if l < self.size() && self.max_heap[l] > self.max_heap[ma] {\n            ma = l;\n        }\n        if r < self.size() && self.max_heap[r] > self.max_heap[ma] {\n            ma = 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\n        if ma == i {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        self.swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    my_heap.c
    /* \u5143\u7d20\u51fa\u5806 */\nint pop(MaxHeap *maxHeap) {\n    // \u5224\u7a7a\u5904\u7406\n    if (isEmpty(maxHeap)) {\n        printf(\"heap is empty!\");\n        return 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\n    swap(maxHeap, 0, size(maxHeap) - 1);\n    // \u5220\u9664\u8282\u70b9\n    int val = maxHeap->data[maxHeap->size - 1];\n    maxHeap->size--;\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    siftDown(maxHeap, 0);\n\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n}\n\n/* \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316 */\nvoid siftDown(MaxHeap *maxHeap, int i) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a max\n        int l = left(maxHeap, i);\n        int r = right(maxHeap, i);\n        int max = i;\n        if (l < size(maxHeap) && maxHeap->data[l] > maxHeap->data[max]) {\n            max = l;\n        }\n        if (r < size(maxHeap) && maxHeap->data[r] > maxHeap->data[max]) {\n            max = 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\n        if (max == i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(maxHeap, i, max);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = max;\n    }\n}\n
    my_heap.zig
    // \u5143\u7d20\u51fa\u5806\nfn pop(self: *Self) !T {\n    // \u5224\u65ad\u5904\u7406\n    if (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\n    try self.swap(0, self.size() - 1);\n    // \u5220\u9664\u8282\u70b9\n    var val = self.max_heap.?.pop();\n    // \u4ece\u9876\u81f3\u5e95\u5806\u5316\n    try self.siftDown(0);\n    // \u8fd4\u56de\u5806\u9876\u5143\u7d20\n    return val;\n} \n\n// \u4ece\u8282\u70b9 i \u5f00\u59cb\uff0c\u4ece\u9876\u81f3\u5e95\u5806\u5316\nfn siftDown(self: *Self, i_: usize) !void {\n    var i = i_;\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        var l = left(i);\n        var r = right(i);\n        var ma = i;\n        if (l < self.size() and self.max_heap.?.items[l] > self.max_heap.?.items[ma]) ma = l;\n        if (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\n        if (ma == i) break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        try self.swap(i, ma);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\n}\n
    "},{"location":"chapter_heap/heap/#813","title":"8.1.3 \u00a0 \u5806\u7684\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\u201c\u5806\u201d\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\u6700\u5927\u7684 \\(k\\) \u4e2a\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\n    heap = []\n    # \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for i in range(k):\n        heapq.heappush(heap, nums[i])\n    # \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for 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\n        if nums[i] > heap[0]:\n            heapq.heappop(heap)\n            heapq.heappush(heap, nums[i])\n    return 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\n    priority_queue<int, vector<int>, greater<int>> heap;\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        heap.push(nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > heap.top()) {\n            heap.pop();\n            heap.push(nums[i]);\n        }\n    }\n    return 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\n    Queue<Integer> heap = new PriorityQueue<Integer>();\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        heap.offer(nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > heap.peek()) {\n            heap.poll();\n            heap.offer(nums[i]);\n        }\n    }\n    return 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\n    PriorityQueue<int, int> heap = new();\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        heap.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\n    for (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\n        if (nums[i] > heap.Peek()) {\n            heap.Dequeue();\n            heap.Enqueue(nums[i], nums[i]);\n        }\n    }\n    return 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\n    h := &minHeap{}\n    heap.Init(h)\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for i := 0; i < k; i++ {\n        heap.Push(h, nums[i])\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for 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\n        if nums[i] > h.Top().(int) {\n            heap.Pop(h)\n            heap.Push(h, nums[i])\n        }\n    }\n    return 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\n    var heap = Heap(nums.prefix(k))\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for 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\n        if nums[i] > heap.min()! {\n            _ = heap.removeMin()\n            heap.insert(nums[i])\n        }\n    }\n    return heap.unordered\n}\n
    top_k.js
    /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap, val) {\n    // \u5143\u7d20\u53d6\u53cd\n    maxHeap.push(-val);\n}\n\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.pop();\n}\n\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.peek();\n}\n\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return maxHeap.getMaxHeap().map((num) => -num);\n}\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\n    const maxHeap = new MaxHeap([]);\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (let i = 0; i < k; i++) {\n        pushMinHeap(maxHeap, nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > peekMinHeap(maxHeap)) {\n            popMinHeap(maxHeap);\n            pushMinHeap(maxHeap, nums[i]);\n        }\n    }\n    // \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\n    return getMinHeap(maxHeap);\n}\n
    top_k.ts
    /* \u5143\u7d20\u5165\u5806 */\nfunction pushMinHeap(maxHeap: MaxHeap, val: number): void {\n    // \u5143\u7d20\u53d6\u53cd\n    maxHeap.push(-val);\n}\n\n/* \u5143\u7d20\u51fa\u5806 */\nfunction popMinHeap(maxHeap: MaxHeap): number {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.pop();\n}\n\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nfunction peekMinHeap(maxHeap: MaxHeap): number {\n    // \u5143\u7d20\u53d6\u53cd\n    return -maxHeap.peek();\n}\n\n/* \u53d6\u51fa\u5806\u4e2d\u5143\u7d20 */\nfunction getMinHeap(maxHeap: MaxHeap): number[] {\n    // \u5143\u7d20\u53d6\u53cd\n    return maxHeap.getMaxHeap().map((num: number) => -num);\n}\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\n    const maxHeap = new MaxHeap([]);\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (let i = 0; i < k; i++) {\n        pushMinHeap(maxHeap, nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > peekMinHeap(maxHeap)) {\n            popMinHeap(maxHeap);\n            pushMinHeap(maxHeap, nums[i]);\n        }\n    }\n    // \u8fd4\u56de\u5806\u4e2d\u5143\u7d20\n    return 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\n  MinHeap 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\n  for (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\n    if (nums[i] > heap.peek()) {\n      heap.pop();\n      heap.push(nums[i]);\n    }\n  }\n  return 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\n    let mut heap = BinaryHeap::<Reverse<i32>>::new();\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for &num in nums.iter().take(k) {\n        heap.push(Reverse(num));\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for &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\n        if num > heap.peek().unwrap().0 {\n            heap.pop();\n            heap.push(Reverse(num));\n        }\n    }\n    heap\n}\n
    top_k.c
    /* \u5143\u7d20\u5165\u5806 */\nvoid pushMinHeap(MaxHeap *maxHeap, int val) {\n    // \u5143\u7d20\u53d6\u53cd\n    push(maxHeap, -val);\n}\n\n/* \u5143\u7d20\u51fa\u5806 */\nint popMinHeap(MaxHeap *maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -pop(maxHeap);\n}\n\n/* \u8bbf\u95ee\u5806\u9876\u5143\u7d20 */\nint peekMinHeap(MaxHeap *maxHeap) {\n    // \u5143\u7d20\u53d6\u53cd\n    return -peek(maxHeap);\n}\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\n    int *res = (int *)malloc(maxHeap->size * sizeof(int));\n    for (int i = 0; i < maxHeap->size; i++) {\n        res[i] = -maxHeap->data[i];\n    }\n    return res;\n}\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\n    int *res = (int *)malloc(maxHeap->size * sizeof(int));\n    for (int i = 0; i < maxHeap->size; i++) {\n        res[i] = -maxHeap->data[i];\n    }\n    return res;\n}\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\n    int *empty = (int *)malloc(0);\n    MaxHeap *maxHeap = newMaxHeap(empty, 0);\n    // \u5c06\u6570\u7ec4\u7684\u524d k \u4e2a\u5143\u7d20\u5165\u5806\n    for (int i = 0; i < k; i++) {\n        pushMinHeap(maxHeap, nums[i]);\n    }\n    // \u4ece\u7b2c k+1 \u4e2a\u5143\u7d20\u5f00\u59cb\uff0c\u4fdd\u6301\u5806\u7684\u957f\u5ea6\u4e3a k\n    for (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\n        if (nums[i] > peekMinHeap(maxHeap)) {\n            popMinHeap(maxHeap);\n            pushMinHeap(maxHeap, nums[i]);\n        }\n    }\n    int *res = getMinHeap(maxHeap);\n    // \u91ca\u653e\u5185\u5b58\n    delMaxHeap(maxHeap);\n    return 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\u7684 \\(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\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\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\u5bf9\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\uff0c\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 \u548c Zig \u7b49\u8bed\u8a00\u3002
    • \u9f13\u52b1\u8bfb\u8005\u5728\u7ebf\u4e0a\u7ae0\u8282\u8bc4\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\u7684\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\u201c\u5927\u795e\u201d\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\u548c\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\u548c\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":"

    \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\uff09\uff1akrahets\u3001codingonion\u3001nuomi1\u3001Gonglja\u3001Reanon\u3001justin-tse\u3001danielsss\u3001hpstory\u3001S-N-O-R-L-A-X\u3001night-cruise\u3001msk397\u3001gvenusleo\u3001RiverTwilight\u3001gyt95\u3001zhuoqinyue\u3001Zuoxun\u3001Xia-Sang\u3001mingXta\u3001FangYuan33\u3001GN-Yu\u3001IsChristina\u3001xBLACKICEx\u3001guowei-gong\u3001Cathay-Chen\u3001mgisr\u3001JoseHung\u3001qualifier1024\u3001pengchzn\u3001Guanngxu\u3001longsizhuo\u3001L-Super\u3001what-is-me\u3001yuan0221\u3001lhxsm\u3001Slone123c\u3001WSL0809\u3001longranger2\u3001theNefelibatas\u3001xiongsp\u3001JeffersonHuang\u3001hongyun-robot\u3001K3v123\u3001yuelinxin\u3001a16su\u3001gaofer\u3001malone6\u3001Wonderdch\u3001xjr7670\u3001DullSword\u3001Horbin-Magician\u3001NI-SW\u3001reeswell\u3001XC-Zero\u3001XiaChuerwu\u3001yd-j\u3001iron-irax\u3001huawuque404\u3001MolDuM\u3001Nigh\u3001KorsChen\u3001foursevenlove\u300152coder\u3001bubble9um\u3001youshaoXG\u3001curly210102\u3001gltianwen\u3001fanchenggang\u3001Transmigration-zhou\u3001FloranceYeh\u3001FreddieLi\u3001ShiMaRing\u3001lipusheng\u3001Javesun99\u3001JackYang-hellobobo\u3001shanghai-Jerry\u30010130w\u3001Keynman\u3001psychelzh\u3001logan-qiu\u3001ZnYang2018\u3001MwumLi\u30011ch0\u3001Phoenix0415\u3001qingpeng9802\u3001Richard-Zhang1019\u3001QiLOL\u3001Suremotoo\u3001Turing-1024-Lee\u3001Evilrabbit520\u3001GaochaoZhu\u3001ZJKung\u3001linzeyan\u3001hezhizhen\u3001ZongYangL\u3001beintentional\u3001czruby\u3001coderlef\u3001dshlstarr\u3001szu17dmy\u3001fbigm\u3001gledfish\u3001hts0000\u3001boloboloda\u3001iStig\u3001jiaxianhua\u3001wenjianmin\u3001keshida\u3001kilikilikid\u3001lclc6\u3001lwbaptx\u3001liuxjerry\u3001lucaswangdev\u3001lyl625760\u3001chadyi\u3001noobcodemaker\u3001selear\u3001siqyka\u3001syd168\u30014yDX3906\u3001tao363\u3001wangwang105\u3001weibk\u3001yabo083\u3001yi427\u3001yishangzhang\u3001zhouLion\u3001baagod\u3001ElaBosak233\u3001xb534\u3001luluxia\u3001yanedie\u3001thomasq0 \u548c YangXuanyi\u3002

    \u672c\u4e66\u7684\u4ee3\u7801\u5ba1\u9605\u5de5\u4f5c\u7531 codingonion, Gonglja\u3001gvenusleo\u3001hpstory\u3001justin\u2010tse\u3001krahets\u3001night-cruise\u3001nuomi1 \u548c Reanon \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

    \u5728\u672c\u4e66\u7684\u521b\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6211\u5f97\u5230\u4e86\u8bb8\u591a\u4eba\u7684\u5e2e\u52a9\u3002

    • \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\u5b8c\u5584\u8d77\u5230\u4e86\u91cd\u8981\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\u7684\u9a71\u4f7f\u4e0b\u591a\u6b21\u8010\u5fc3\u4fee\u6539\uff1b
    • \u611f\u8c22 @squidfunk \u63d0\u4f9b\u7684\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\u6211\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 \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 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\n# \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\n// \u5185\u5bb9\u6ce8\u91ca\uff0c\u7528\u4e8e\u8be6\u89e3\u4ee3\u7801\n\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\u4ee5\u56fe\u89e3\u5f62\u5f0f\u5c55\u793a\uff0c\u800c\u6587\u5b57\u5219\u4f5c\u4e3a\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\u7f51\u9875\u7248\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\u4f60\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\u548c\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\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\u8bc4\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\n    i, 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\n    while 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\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        elif nums[m] > target:\n            j = m - 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        else:\n            return m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    i, 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\n    for i <= j {\n        m := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i = 0\n    var 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\n    while i <= j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    let i = 0,\n        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\n    while (i <= j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\n        const m = parseInt(i + (j - i) / 2);\n        if (nums[m] < target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else 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\n    return -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\n    let i = 0,\n        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\n    while (i <= j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        const m = Math.floor(i + (j - i) / 2);\n        if (nums[m] < target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        } else if (nums[m] > target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        } else {\n            // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }\n    }\n    return -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\n  int 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\n  while (i <= j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n      i = m + 1;\n    } else if (nums[m] > target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n      j = m - 1;\n    } else {\n      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n      return m;\n    }\n  }\n  // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n  return -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\n    let mut i = 0;\n    let 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\n    while i <= j {\n        let m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        } else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        } else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }                       \n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i: usize = 0;\n    var 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\n    while (i <= j) {\n        var m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1;\n        } else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1;\n        } else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return @intCast(m);\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -1;\n}\n

    \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(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\u4e3a \\(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\n    i, 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\n    while i < j:\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n        elif nums[m] > target:\n            j = m  # \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n        else:\n            return m  # \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2;   // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else                       // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    i, 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\n    for i < j {\n        m := i + (j-i)/2      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i = 0\n    var 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\n    while i < j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1\n        } else if nums[m] > target { // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m\n        } else { // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    let i = 0,\n        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\n    while (i < j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m \uff0c\u4f7f\u7528 parseInt() \u5411\u4e0b\u53d6\u6574\n        const m = parseInt(i + (j - i) / 2);\n        if (nums[m] < target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target)\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n        else return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    let i = 0,\n        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\n    while (i < j) {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        const m = Math.floor(i + (j - i) / 2);\n        if (nums[m] < target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        } else if (nums[m] > target) {\n            // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        } else {\n            // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }\n    }\n    return -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\n  int 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\n  while (i < j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n      i = m + 1;\n    } else if (nums[m] > target) {\n      // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n      j = m;\n    } else {\n      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n      return m;\n    }\n  }\n  // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n  return -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\n    let mut i = 0;\n    let 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\n    while i < j {\n        let m = i + (j - i) / 2;      // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {         // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        } else if nums[m as usize] > target {  // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        } else {                      // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n        }                       \n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    int 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\n    while (i < j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target)    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        else if (nums[m] > target) // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        else // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return m;\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    var i: usize = 0;\n    var 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\n    while (i <= j) {\n        var m = i + (j - i) / 2;                // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums.items[m] < target) {           // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [m+1, j) \u4e2d\n            i = m + 1;\n        } else if (nums.items[m] > target) {    // \u6b64\u60c5\u51b5\u8bf4\u660e target \u5728\u533a\u95f4 [i, m) \u4e2d\n            j = m;\n        } else {                                // \u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de\u5176\u7d22\u5f15\n            return @intCast(m);\n        }\n    }\n    // \u672a\u627e\u5230\u76ee\u6807\u5143\u7d20\uff0c\u8fd4\u56de -1\n    return -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\n    i = binary_search_insertion(nums, target)\n    # \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == len(nums) or nums[i] != target:\n        return -1\n    # \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    int i = binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == nums.size() || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    int i = binary_search_insertion.binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == nums.length || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    int i = binary_search_insertion.BinarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == nums.Length || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    i := binarySearchInsertion(nums, target)\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == len(nums) || nums[i] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    let i = binarySearchInsertion(nums: nums, target: target)\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == nums.count || nums[i] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    const i = binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i === nums.length || nums[i] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    const i = binarySearchInsertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i === nums.length || nums[i] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n  int i = binarySearchInsertion(nums, target);\n  // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n  if (i == nums.length || nums[i] != target) {\n    return -1;\n  }\n  // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n  return 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\n    let i = binary_search_insertion(nums, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if i == nums.len() as i32 || nums[i as usize] != target {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    i\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\n    int i = binarySearchInsertion(nums, numSize, target);\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (i == numSize || nums[i] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 i\n    return 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\n    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\n    j = i - 1\n    # \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 or nums[j] != target:\n        return -1\n    # \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    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\n    j := i - 1\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 || nums[j] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    let 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\n    let j = i - 1\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 || nums[j] != target {\n        return -1\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    const 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\n    const j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j === -1 || nums[j] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n    const 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\n    const j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j === -1 || nums[j] !== target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\n  int 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\n  int j = i - 1;\n  // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n  if (j == -1 || nums[j] != target) {\n    return -1;\n  }\n  // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n  return 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\n    let 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\n    let j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if j == -1 || nums[j as usize] != target {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    j\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\n    int 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\n    int j = i - 1;\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de -1\n    if (j == -1 || nums[j] != target) {\n        return -1;\n    }\n    // \u627e\u5230 target \uff0c\u8fd4\u56de\u7d22\u5f15 j\n    return 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\uff08Python \u65e0\u987b\u6539\u52a8\uff09\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\u793a\u4f8b\u5982\u56fe 10-4 \u6240\u793a\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\"\"\"\n    i, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j:\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        elif nums[m] > target:\n            j = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        else:\n            return m  # \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n    # \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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) {\n    int i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n    int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n    int i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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]\n    i, j := 0, len(nums)-1\n    for i <= j {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        m := i + (j-i)/2\n        if nums[m] < target {\n            // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target {\n            // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else {\n            // \u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 m\n            return m\n        }\n    }\n    // \u672a\u627e\u5230 target \uff0c\u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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 {\n    var i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target {\n            i = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m] > target {\n            j = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return i;\n}\n
    binary_search_insertion.ts
    /* \u4e8c\u5206\u67e5\u627e\u63d2\u5165\u70b9\uff08\u65e0\u91cd\u590d\u5143\u7d20\uff09 */\nfunction binarySearchInsertionSimple(\n    nums: Array<number>,\n    target: number\n): number {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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) {\n  int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n  while (i <= j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n    } else if (nums[m] > target) {\n      j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n    } else {\n      return 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\n  return 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 {\n    let (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {\n            i = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m as usize] > target {\n            j = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    i\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) {\n    int i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            return 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\n    return 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\"\"\"\n    i, j = 0, len(nums) - 1  # \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j:\n        m = (i + j) // 2  # \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target:\n            i = m + 1  # target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        elif nums[m] > target:\n            j = m - 1  # target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        else:\n            j = m - 1  # \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n    # \u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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) {\n    int i = 0, j = nums.size() - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n    int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n    int i = 0, j = nums.Length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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]\n    i, j := 0, len(nums)-1\n    for i <= j {\n        // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        m := i + (j-i)/2\n        if nums[m] < target {\n            // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n            i = m + 1\n        } else if nums[m] > target {\n            // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        } else {\n            // \u9996\u4e2a\u5c0f\u4e8e target \u7684\u5143\u7d20\u5728\u533a\u95f4 [i, m-1] \u4e2d\n            j = m - 1\n        }\n    }\n    // \u8fd4\u56de\u63d2\u5165\u70b9 i\n    return 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 {\n    var i = 0, j = nums.count - 1 // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2 // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m] < target {\n            i = m + 1 // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m] > target {\n            j = m - 1 // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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 {\n    let i = 0,\n        j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        const m = Math.floor(i + (j - i) / 2); // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m, \u4f7f\u7528 Math.floor() \u5411\u4e0b\u53d6\u6574\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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) {\n  int i = 0, j = nums.length - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n  while (i <= j) {\n    int m = i + (j - i) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n    if (nums[m] < target) {\n      i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n    } else if (nums[m] > target) {\n      j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n    } else {\n      j = 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\n  return 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 {\n    let (mut i, mut j) = (0, nums.len() as i32 - 1);    // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while i <= j {\n        let m = i + (j - i) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if nums[m as usize] < target {\n            i = m + 1;  // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if nums[m as usize] > target {\n            j = m - 1;  // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    i\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) {\n    int i = 0, j = numSize - 1; // \u521d\u59cb\u5316\u53cc\u95ed\u533a\u95f4 [0, n-1]\n    while (i <= j) {\n        int m = i + (j - i) / 2; // \u8ba1\u7b97\u4e2d\u70b9\u7d22\u5f15 m\n        if (nums[m] < target) {\n            i = m + 1; // target \u5728\u533a\u95f4 [m+1, j] \u4e2d\n        } else if (nums[m] > target) {\n            j = m - 1; // target \u5728\u533a\u95f4 [i, m-1] \u4e2d\n        } else {\n            j = 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\n    return 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)\n    for i in range(len(nums) - 1):\n        for j in range(i + 1, len(nums)):\n            if nums[i] + nums[j] == target:\n                return [i, j]\n    return []\n
    two_sum.cpp
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nvector<int> twoSumBruteForce(vector<int> &nums, int target) {\n    int size = nums.size();\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (int i = 0; i < size - 1; i++) {\n        for (int j = i + 1; j < size; j++) {\n            if (nums[i] + nums[j] == target)\n                return {i, j};\n        }\n    }\n    return {};\n}\n
    two_sum.java
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] twoSumBruteForce(int[] nums, int target) {\n    int size = nums.length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (int i = 0; i < size - 1; i++) {\n        for (int j = i + 1; j < size; j++) {\n            if (nums[i] + nums[j] == target)\n                return new int[] { i, j };\n        }\n    }\n    return new int[0];\n}\n
    two_sum.cs
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint[] TwoSumBruteForce(int[] nums, int target) {\n    int size = nums.Length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (int i = 0; i < size - 1; i++) {\n        for (int j = i + 1; j < size; j++) {\n            if (nums[i] + nums[j] == target)\n                return [i, j];\n        }\n    }\n    return [];\n}\n
    two_sum.go
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunc twoSumBruteForce(nums []int, target int) []int {\n    size := len(nums)\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for i := 0; i < size-1; i++ {\n        for j := i + 1; i < size; j++ {\n            if nums[i]+nums[j] == target {\n                return []int{i, j}\n            }\n        }\n    }\n    return 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)\n    for i in nums.indices.dropLast() {\n        for j in nums.indices.dropFirst(i + 1) {\n            if nums[i] + nums[j] == target {\n                return [i, j]\n            }\n        }\n    }\n    return [0]\n}\n
    two_sum.js
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums, target) {\n    const n = nums.length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (let i = 0; i < n; i++) {\n        for (let j = i + 1; j < n; j++) {\n            if (nums[i] + nums[j] === target) {\n                return [i, j];\n            }\n        }\n    }\n    return [];\n}\n
    two_sum.ts
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nfunction twoSumBruteForce(nums: number[], target: number): number[] {\n    const n = nums.length;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for (let i = 0; i < n; i++) {\n        for (let j = i + 1; j < n; j++) {\n            if (nums[i] + nums[j] === target) {\n                return [i, j];\n            }\n        }\n    }\n    return [];\n}\n
    two_sum.dart
    /* \u65b9\u6cd5\u4e00\uff1a \u66b4\u529b\u679a\u4e3e */\nList<int> twoSumBruteForce(List<int> nums, int target) {\n  int size = nums.length;\n  // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n  for (var i = 0; i < size - 1; i++) {\n    for (var j = i + 1; j < size; j++) {\n      if (nums[i] + nums[j] == target) return [i, j];\n    }\n  }\n  return [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>> {\n    let size = nums.len();\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    for i in 0..size - 1 {\n        for j in i + 1..size {\n            if nums[i] + nums[j] == target {\n                return Some(vec![i as i32, j as i32]);\n            }\n        }\n    }\n    None\n}\n
    two_sum.c
    /* \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e */\nint *twoSumBruteForce(int *nums, int numsSize, int target, int *returnSize) {\n    for (int i = 0; i < numsSize; ++i) {\n        for (int j = i + 1; j < numsSize; ++j) {\n            if (nums[i] + nums[j] == target) {\n                int *res = malloc(sizeof(int) * 2);\n                res[0] = i, res[1] = j;\n                *returnSize = 2;\n                return res;\n            }\n        }\n    }\n    *returnSize = 0;\n    return NULL;\n}\n
    two_sum.zig
    // \u65b9\u6cd5\u4e00\uff1a\u66b4\u529b\u679a\u4e3e\nfn twoSumBruteForce(nums: []i32, target: i32) ?[2]i32 {\n    var size: usize = nums.len;\n    var i: usize = 0;\n    // \u4e24\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n^2)\n    while (i < size - 1) : (i += 1) {\n        var j = i + 1;\n        while (j < size) : (j += 1) {\n            if (nums[i] + nums[j] == target) {\n                return [_]i32{@intCast(i), @intCast(j)};\n            }\n        }\n    }\n    return 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)\n    dic = {}\n    # \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for i in range(len(nums)):\n        if target - nums[i] in dic:\n            return [dic[target - nums[i]], i]\n        dic[nums[i]] = i\n    return []\n
    two_sum.cpp
    /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nvector<int> twoSumHashTable(vector<int> &nums, int target) {\n    int size = nums.size();\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    unordered_map<int, int> dic;\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (int i = 0; i < size; i++) {\n        if (dic.find(target - nums[i]) != dic.end()) {\n            return {dic[target - nums[i]], i};\n        }\n        dic.emplace(nums[i], i);\n    }\n    return {};\n}\n
    two_sum.java
    /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] twoSumHashTable(int[] nums, int target) {\n    int size = nums.length;\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    Map<Integer, Integer> dic = new HashMap<>();\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (int i = 0; i < size; i++) {\n        if (dic.containsKey(target - nums[i])) {\n            return new int[] { dic.get(target - nums[i]), i };\n        }\n        dic.put(nums[i], i);\n    }\n    return new int[0];\n}\n
    two_sum.cs
    /* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint[] TwoSumHashTable(int[] nums, int target) {\n    int size = nums.Length;\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    Dictionary<int, int> dic = [];\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (int i = 0; i < size; i++) {\n        if (dic.ContainsKey(target - nums[i])) {\n            return [dic[target - nums[i]], i];\n        }\n        dic.Add(nums[i], i);\n    }\n    return [];\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)\n    hashTable := map[int]int{}\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for idx, val := range nums {\n        if preIdx, ok := hashTable[target-val]; ok {\n            return []int{preIdx, idx}\n        }\n        hashTable[val] = idx\n    }\n    return 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)\n    var dic: [Int: Int] = [:]\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for i in nums.indices {\n        if let j = dic[target - nums[i]] {\n            return [j, i]\n        }\n        dic[nums[i]] = i\n    }\n    return [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)\n    let m = {};\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (let i = 0; i < nums.length; i++) {\n        if (m[target - nums[i]] !== undefined) {\n            return [m[target - nums[i]], i];\n        } else {\n            m[nums[i]] = i;\n        }\n    }\n    return [];\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)\n    let m: Map<number, number> = new Map();\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (let i = 0; i < nums.length; i++) {\n        let index = m.get(target - nums[i]);\n        if (index !== undefined) {\n            return [index, i];\n        } else {\n            m.set(nums[i], i);\n        }\n    }\n    return [];\n}\n
    two_sum.dart
    /* \u65b9\u6cd5\u4e8c\uff1a \u8f85\u52a9\u54c8\u5e0c\u8868 */\nList<int> twoSumHashTable(List<int> nums, int target) {\n  int size = nums.length;\n  // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n  Map<int, int> dic = HashMap();\n  // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n  for (var i = 0; i < size; i++) {\n    if (dic.containsKey(target - nums[i])) {\n      return [dic[target - nums[i]]!, i];\n    }\n    dic.putIfAbsent(nums[i], () => i);\n  }\n  return [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)\n    let mut dic = HashMap::new();\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    for (i, num) in nums.iter().enumerate() {\n        match dic.get(&(target - num)) {\n            Some(v) => return Some(vec![*v as i32, i as i32]),\n            None => dic.insert(num, i as i32)\n        };\n    }\n    None\n}\n
    two_sum.c
    /* \u54c8\u5e0c\u8868 */\ntypedef struct {\n    int key;\n    int val;\n    UT_hash_handle hh; // \u57fa\u4e8e uthash.h \u5b9e\u73b0\n} HashTable;\n\n/* \u54c8\u5e0c\u8868\u67e5\u8be2 */\nHashTable *find(HashTable *h, int key) {\n    HashTable *tmp;\n    HASH_FIND_INT(h, &key, tmp);\n    return tmp;\n}\n\n/* \u54c8\u5e0c\u8868\u5143\u7d20\u63d2\u5165 */\nvoid insert(HashTable *h, int key, int val) {\n    HashTable *t = find(h, key);\n    if (t == NULL) {\n        HashTable *tmp = malloc(sizeof(HashTable));\n        tmp->key = key, tmp->val = val;\n        HASH_ADD_INT(h, key, tmp);\n    } else {\n        t->val = val;\n    }\n}\n\n/* \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868 */\nint *twoSumHashTable(int *nums, int numsSize, int target, int *returnSize) {\n    HashTable *hashtable = NULL;\n    for (int i = 0; i < numsSize; i++) {\n        HashTable *t = find(hashtable, target - nums[i]);\n        if (t != NULL) {\n            int *res = malloc(sizeof(int) * 2);\n            res[0] = t->val, res[1] = i;\n            *returnSize = 2;\n            return res;\n        }\n        insert(hashtable, nums[i], i);\n    }\n    *returnSize = 0;\n    return NULL;\n}\n
    two_sum.zig
    // \u65b9\u6cd5\u4e8c\uff1a\u8f85\u52a9\u54c8\u5e0c\u8868\nfn twoSumHashTable(nums: []i32, target: i32) !?[2]i32 {\n    var size: usize = nums.len;\n    // \u8f85\u52a9\u54c8\u5e0c\u8868\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    var dic = std.AutoHashMap(i32, i32).init(std.heap.page_allocator);\n    defer dic.deinit();\n    var i: usize = 0;\n    // \u5355\u5c42\u5faa\u73af\uff0c\u65f6\u95f4\u590d\u6742\u5ea6\u4e3a O(n)\n    while (i < size) : (i += 1) {\n        if (dic.contains(target - nums[i])) {\n            return [_]i32{dic.get(target - nums[i]).?, @intCast(i)};\n        }\n        try dic.put(nums[i], @intCast(i));\n    }\n    return 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\u7684\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\u3002
    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\"\"\"\n    n = len(nums)\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for 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\n        for j in range(i):\n            if nums[j] > nums[j + 1]:\n                # \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[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]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                // \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\n                swap(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]\n    for (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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    for (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 \n        for (int j = 0; j < i; j++) {\n            if (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]\n    for 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\n        for j := 0; j < i; j++ {\n            if nums[j] > nums[j+1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[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]\n    for 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 \n        for j in stride(from: 0, to: i, by: 1) {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j]\n                nums[j] = nums[j + 1]\n                nums[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]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    for (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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n  for (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\n    for (int j = 0; j < i; j++) {\n      if (nums[j] > nums[j + 1]) {\n        // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n        int tmp = nums[j];\n        nums[j] = nums[j + 1];\n        nums[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]\n    for 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 \n        for j in 0..i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    for (int i = 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                int temp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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]\n    var i: usize = nums.len - 1;\n    while (i > 0) : (i -= 1) {\n        var 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 \n        while (j < i) : (j += 1) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                var tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[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\"\"\"\n    n = len(nums)\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [0, i]\n    for i in range(n - 1, 0, -1):\n        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\n        for j in range(i):\n            if nums[j] > nums[j + 1]:\n                # \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[j], nums[j + 1] = nums[j + 1], nums[j]\n                flag = True  # \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n        if not flag:\n            break  # \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = nums.size() - 1; i > 0; i--) {\n        bool 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                // \u8fd9\u91cc\u4f7f\u7528\u4e86 std::swap() \u51fd\u6570\n                swap(nums[j], nums[j + 1]);\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag)\n            break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = nums.length - 1; i > 0; i--) {\n        boolean 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                int tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag)\n            break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = nums.Length - 1; i > 0; i--) {\n        bool 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 \n        for (int j = 0; j < i; j++) {\n            if (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                flag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag) break;     // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for i := len(nums) - 1; i > 0; i-- {\n        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\n        for j := 0; j < i; j++ {\n            if nums[j] > nums[j+1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                nums[j], nums[j+1] = nums[j+1], nums[j]\n                flag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if flag == false { // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n            break\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]\n    for i in stride(from: nums.count - 1, to: 0, by: -1) {\n        var flag = false // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n        for j in stride(from: 0, to: i, by: 1) {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j]\n                nums[j] = nums[j + 1]\n                nums[j + 1] = tmp\n                flag = true // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if !flag { // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\u672a\u4ea4\u6362\u4efb\u4f55\u5143\u7d20\uff0c\u76f4\u63a5\u8df3\u51fa\n            break\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]\n    for (let i = nums.length - 1; i > 0; i--) {\n        let 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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag) break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (let i = nums.length - 1; i > 0; i--) {\n        let 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\n        for (let j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if (!flag) break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n  for (int i = nums.length - 1; i > 0; i--) {\n    bool 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\n    for (int j = 0; j < i; j++) {\n      if (nums[j] > nums[j + 1]) {\n        // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n        int tmp = nums[j];\n        nums[j] = nums[j + 1];\n        nums[j + 1] = tmp;\n        flag = true; // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n      }\n    }\n    if (!flag) break; // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for i in (1..nums.len()).rev() {\n        let 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 \n        for j in 0..i {\n            if nums[j] > nums[j + 1] {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                let tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true;  // \u8bb0\u5f55\u4ea4\u6362\u5143\u7d20\n            }\n        }\n        if !flag {break};  // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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]\n    for (int i = size - 1; i > 0; i--) {\n        bool 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\n        for (int j = 0; j < i; j++) {\n            if (nums[j] > nums[j + 1]) {\n                int temp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = temp;\n                flag = true;\n            }\n        }\n        if (!flag)\n            break;\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]\n    var i: usize = nums.len - 1;\n    while (i > 0) : (i -= 1) {\n        var flag = false;   // \u521d\u59cb\u5316\u6807\u5fd7\u4f4d\n        var 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 \n        while (j < i) : (j += 1) {\n            if (nums[j] > nums[j + 1]) {\n                // \u4ea4\u6362 nums[j] \u4e0e nums[j + 1]\n                var tmp = nums[j];\n                nums[j] = nums[j + 1];\n                nums[j + 1] = tmp;\n                flag = true;\n            }\n        }\n        if (!flag) break;   // \u6b64\u8f6e\u201c\u5192\u6ce1\u201d\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\n    k = len(nums) // 2\n    buckets = [[] for _ in range(k)]\n    # 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for 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]\n        i = int(num * k)\n        # \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].append(num)\n    # 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        bucket.sort()\n    # 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    i = 0\n    for bucket in buckets:\n        for num in bucket:\n            nums[i] = num\n            i += 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\n    int k = nums.size() / 2;\n    vector<vector<float>> buckets(k);\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        int i = num * k;\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\n        buckets[i].push_back(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        sort(bucket.begin(), bucket.end());\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    int i = 0;\n    for (vector<float> &bucket : buckets) {\n        for (float num : bucket) {\n            nums[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\n    int k = nums.length / 2;\n    List<List<Float>> buckets = new ArrayList<>();\n    for (int i = 0; i < k; i++) {\n        buckets.add(new ArrayList<>());\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        int i = (int) (num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets.get(i).add(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        Collections.sort(bucket);\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    int i = 0;\n    for (List<Float> bucket : buckets) {\n        for (float num : bucket) {\n            nums[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\n    int k = nums.Length / 2;\n    List<List<float>> buckets = [];\n    for (int i = 0; i < k; i++) {\n        buckets.Add([]);\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    foreach (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]\n        int i = (int)(num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].Add(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    foreach (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\n        bucket.Sort();\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    int j = 0;\n    foreach (List<float> bucket in buckets) {\n        foreach (float num in bucket) {\n            nums[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\n    k := len(nums) / 2\n    buckets := make([][]float64, k)\n    for i := 0; i < k; i++ {\n        buckets[i] = make([]float64, 0)\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for _, 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]\n        i := int(num * float64(k))\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i] = append(buckets[i], num)\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        sort.Float64s(buckets[i])\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    i := 0\n    for _, bucket := range buckets {\n        for _, num := range bucket {\n            nums[i] = num\n            i++\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\n    let k = nums.count / 2\n    var buckets = (0 ..< k).map { _ in [Double]() }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for 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]\n        let i = Int(num * Double(k))\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].append(num)\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        buckets[i].sort()\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    var i = nums.startIndex\n    for bucket in buckets {\n        for num in bucket {\n            nums[i] = num\n            nums.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\n    const k = nums.length / 2;\n    const buckets = [];\n    for (let i = 0; i < k; i++) {\n        buckets.push([]);\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        const i = Math.floor(num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].push(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        bucket.sort((a, b) => a - b);\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    let i = 0;\n    for (const bucket of buckets) {\n        for (const num of bucket) {\n            nums[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\n    const k = nums.length / 2;\n    const buckets: number[][] = [];\n    for (let i = 0; i < k; i++) {\n        buckets.push([]);\n    }\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        const i = Math.floor(num * k);\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].push(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (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\n        bucket.sort((a, b) => a - b);\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    let i = 0;\n    for (const bucket of buckets) {\n        for (const num of bucket) {\n            nums[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\n  int k = nums.length ~/ 2;\n  List<List<double>> buckets = List.generate(k, (index) => []);\n\n  // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n  for (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]\n    int i = (_num * k).toInt();\n    // \u5c06 _num \u6dfb\u52a0\u8fdb\u6876 bucket_idx\n    buckets[i].add(_num);\n  }\n  // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n  for (List<double> bucket in buckets) {\n    bucket.sort();\n  }\n  // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n  int i = 0;\n  for (List<double> bucket in buckets) {\n    for (double _num in bucket) {\n      nums[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\n    let k = nums.len() / 2;\n    let mut buckets = vec![vec![]; k];\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for &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]\n        let i = (num * k as f64) as usize;\n        // \u5c06 num \u6dfb\u52a0\u8fdb\u6876 i\n        buckets[i].push(num);\n    }\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for 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\n        bucket.sort_by(|a, b| a.partial_cmp(b).unwrap());\n    }\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    let mut i = 0;\n    for bucket in &mut buckets {\n        for &mut num in bucket {\n            nums[i] = num;\n            i += 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\n    int k = size / 2;\n    float **buckets = calloc(k, sizeof(float *));\n    for (int i = 0; i < k; i++) {\n        // \u6bcf\u4e2a\u6876\u6700\u591a\u53ef\u4ee5\u5206\u914d k \u4e2a\u5143\u7d20\n        buckets[i] = calloc(ARRAY_SIZE, sizeof(float));\n    }\n\n    // 1. \u5c06\u6570\u7ec4\u5143\u7d20\u5206\u914d\u5230\u5404\u4e2a\u6876\u4e2d\n    for (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]\n        int bucket_idx = nums[i] * k;\n        int 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\n        while (buckets[bucket_idx][j] > 0 && buckets[bucket_idx][j] < nums[i]) {\n            j++;\n        }\n        float temp = nums[i];\n        while (j < ARRAY_SIZE && buckets[bucket_idx][j] > 0) {\n            swap(&temp, &buckets[bucket_idx][j]);\n            j++;\n        }\n        buckets[bucket_idx][j] = temp;\n    }\n\n    // 2. \u5bf9\u5404\u4e2a\u6876\u6267\u884c\u6392\u5e8f\n    for (int i = 0; i < k; i++) {\n        qsort(buckets[i], ARRAY_SIZE, sizeof(float), compare_float);\n    }\n\n    // 3. \u904d\u5386\u6876\u5408\u5e76\u7ed3\u679c\n    for (int i = 0, j = 0; j < k; j++) {\n        for (int l = 0; l < ARRAY_SIZE; l++) {\n            if (buckets[j][l] > 0) {\n                nums[i++] = buckets[j][l];\n            }\n        }\n    }\n\n    // \u91ca\u653e\u4e0a\u8ff0\u5206\u914d\u7684\u5185\u5b58\n    for (int i = 0; i < k; i++) {\n        free(buckets[i]);\n    }\n    free(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\u4e3a \\(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\u4e3a \\(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\n    m = 0\n    for num in nums:\n        m = 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\n    counter = [0] * (m + 1)\n    for num in nums:\n        counter[num] += 1\n    # 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    i = 0\n    for num in range(m + 1):\n        for _ in range(counter[num]):\n            nums[i] = num\n            i += 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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    vector<int> counter(m + 1, 0);\n    for (int num : nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    for (int num : nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    int m = 0;\n    foreach (int num in nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    foreach (int num in nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    m := 0\n    for _, num := range nums {\n        if num > m {\n            m = 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\n    counter := make([]int, m+1)\n    for _, num := range nums {\n        counter[num]++\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    for i, num := 0, 0; num < m+1; num++ {\n        for j := 0; j < counter[num]; j++ {\n            nums[i] = num\n            i++\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\n    let 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\n    var counter = Array(repeating: 0, count: m + 1)\n    for num in nums {\n        counter[num] += 1\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    var i = 0\n    for num in stride(from: 0, to: m + 1, by: 1) {\n        for _ in stride(from: 0, to: counter[num], by: 1) {\n            nums[i] = num\n            i += 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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter = new Array(m + 1).fill(0);\n    for (const num of nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    let i = 0;\n    for (let num = 0; num < m + 1; num++) {\n        for (let j = 0; j < counter[num]; j++, i++) {\n            nums[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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter: number[] = new Array<number>(m + 1).fill(0);\n    for (const num of nums) {\n        counter[num]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    let i = 0;\n    for (let num = 0; num < m + 1; num++) {\n        for (let j = 0; j < counter[num]; j++, i++) {\n            nums[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\n  int m = 0;\n  for (int _num in nums) {\n    m = 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\n  List<int> counter = List.filled(m + 1, 0);\n  for (int _num in nums) {\n    counter[_num]++;\n  }\n  // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n  int i = 0;\n  for (int _num = 0; _num < m + 1; _num++) {\n    for (int j = 0; j < counter[_num]; j++, i++) {\n      nums[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\n    let 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\n    let mut counter = vec![0; m as usize + 1];\n    for &num in &*nums {\n        counter[num as usize] += 1;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    let mut i = 0;\n    for num in 0..m + 1 {\n        for _ in 0..counter[num as usize] {\n            nums[i] = num;\n            i += 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\n    int m = 0;\n    for (int i = 0; i < size; i++) {\n        if (nums[i] > m) {\n            m = 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\n    int *counter = calloc(m + 1, sizeof(int));\n    for (int i = 0; i < size; i++) {\n        counter[nums[i]]++;\n    }\n    // 3. \u904d\u5386 counter \uff0c\u5c06\u5404\u5143\u7d20\u586b\u5165\u539f\u6570\u7ec4 nums\n    int i = 0;\n    for (int num = 0; num < m + 1; num++) {\n        for (int j = 0; j < counter[num]; j++, i++) {\n            nums[i] = num;\n        }\n    }\n    // 4. \u91ca\u653e\u5185\u5b58\n    free(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\n    m = 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\n    counter = [0] * (m + 1)\n    for num in nums:\n        counter[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\n    for i in range(m):\n        counter[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\n    n = len(nums)\n    res = [0] * n\n    for i in range(n - 1, -1, -1):\n        num = nums[i]\n        res[counter[num] - 1] = num  # \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for i in range(n):\n        nums[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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    vector<int> counter(m + 1, 0);\n    for (int num : nums) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int n = nums.size();\n    vector<int> res(n);\n    for (int i = n - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    nums = 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\n    int m = 0;\n    for (int num : nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    for (int num : nums) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int n = nums.length;\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (int i = 0; i < n; i++) {\n        nums[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\n    int m = 0;\n    foreach (int num in nums) {\n        m = 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\n    int[] counter = new int[m + 1];\n    foreach (int num in nums) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int n = nums.Length;\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (int i = 0; i < n; i++) {\n        nums[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\n    m := 0\n    for _, num := range nums {\n        if num > m {\n            m = 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\n    counter := make([]int, m+1)\n    for _, num := range nums {\n        counter[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\n    for i := 0; i < m; i++ {\n        counter[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\n    n := len(nums)\n    res := make([]int, n)\n    for i := n - 1; i >= 0; i-- {\n        num := nums[i]\n        // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        res[counter[num]-1] = num\n        // \u4ee4\u524d\u7f00\u548c\u81ea\u51cf 1 \uff0c\u5f97\u5230\u4e0b\u6b21\u653e\u7f6e num \u7684\u7d22\u5f15\n        counter[num]--\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u6570\u7ec4 res \u8986\u76d6\u539f\u6570\u7ec4 nums\n    copy(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\n    let 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\n    var counter = Array(repeating: 0, count: m + 1)\n    for num in nums {\n        counter[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\n    for i in stride(from: 0, to: m, by: 1) {\n        counter[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\n    var res = Array(repeating: 0, count: nums.count)\n    for i in stride(from: nums.count - 1, through: 0, by: -1) {\n        let num = nums[i]\n        res[counter[num] - 1] = num // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for i in stride(from: 0, to: nums.count, by: 1) {\n        nums[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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter = new Array(m + 1).fill(0);\n    for (const num of nums) {\n        counter[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\n    for (let i = 0; i < m; i++) {\n        counter[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\n    const n = nums.length;\n    const res = new Array(n);\n    for (let i = n - 1; i >= 0; i--) {\n        const num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (let i = 0; i < n; i++) {\n        nums[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\n    let m = 0;\n    for (const num of nums) {\n        m = 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\n    const counter: number[] = new Array<number>(m + 1).fill(0);\n    for (const num of nums) {\n        counter[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\n    for (let i = 0; i < m; i++) {\n        counter[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\n    const n = nums.length;\n    const res: number[] = new Array<number>(n);\n    for (let i = n - 1; i >= 0; i--) {\n        const num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for (let i = 0; i < n; i++) {\n        nums[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\n  int m = 0;\n  for (int _num in nums) {\n    m = 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\n  List<int> counter = List.filled(m + 1, 0);\n  for (int _num in nums) {\n    counter[_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\n  for (int i = 0; i < m; i++) {\n    counter[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\n  int n = nums.length;\n  List<int> res = List.filled(n, 0);\n  for (int i = n - 1; i >= 0; i--) {\n    int _num = nums[i];\n    res[counter[_num] - 1] = _num; // \u5c06 _num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n    counter[_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\n  nums.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\n    let 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\n    let mut counter = vec![0; m as usize + 1];\n    for &num in &*nums {\n        counter[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\n    for i in 0..m as usize {\n        counter[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\n    let n = nums.len();\n    let mut res = vec![0; n];\n    for i in (0..n).rev() {\n        let num = nums[i];\n        res[counter[num as usize] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    for i in 0..n {\n        nums[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\n    int m = 0;\n    for (int i = 0; i < size; i++) {\n        if (nums[i] > m) {\n            m = 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\n    int *counter = calloc(m, sizeof(int));\n    for (int i = 0; i < size; i++) {\n        counter[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\n    for (int i = 0; i < m; i++) {\n        counter[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\n    int *res = malloc(sizeof(int) * size);\n    for (int i = size - 1; i >= 0; i--) {\n        int num = nums[i];\n        res[counter[num] - 1] = num; // \u5c06 num \u653e\u7f6e\u5230\u5bf9\u5e94\u7d22\u5f15\u5904\n        counter[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\n    memcpy(nums, res, size * sizeof(int));\n    // 5. \u91ca\u653e\u5185\u5b58\n    free(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\u4e3a \\(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\u4e3a \\(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\"\"\"\n    while True:\n        # \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        l = 2 * i + 1\n        r = 2 * i + 2\n        ma = i\n        if l < n and nums[l] > nums[ma]:\n            ma = l\n        if r < n and nums[r] > nums[ma]:\n            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\n        if ma == i:\n            break\n        # \u4ea4\u6362\u4e24\u8282\u70b9\n        nums[i], nums[ma] = nums[ma], nums[i]\n        # \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n\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\n    for i in range(len(nums) // 2 - 1, -1, -1):\n        sift_down(nums, len(nums), i)\n    # \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\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\n        sift_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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        swap(nums[i], nums[ma]);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = nums.size() / 2 - 1; i >= 0; --i) {\n        siftDown(nums, nums.size(), i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        swap(nums[0], nums[i]);\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i)\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        int temp = nums[i];\n        nums[i] = nums[ma];\n        nums[ma] = temp;\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = nums.length / 2 - 1; i >= 0; i--) {\n        siftDown(nums, nums.length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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        int tmp = nums[0];\n        nums[0] = nums[i];\n        nums[i] = tmp;\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i)\n            break;\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        (nums[ma], nums[i]) = (nums[i], nums[ma]);\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = nums.Length / 2 - 1; i >= 0; i--) {\n        SiftDown(nums, nums.Length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        SiftDown(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) {\n    for true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        l := 2*i + 1\n        r := 2*i + 2\n        ma := i\n        if l < n && (*nums)[l] > (*nums)[ma] {\n            ma = l\n        }\n        if r < n && (*nums)[r] > (*nums)[ma] {\n            ma = 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\n        if ma == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        (*nums)[i], (*nums)[ma] = (*nums)[ma], (*nums)[i]\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n    }\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\n    for i := len(*nums)/2 - 1; i >= 0; i-- {\n        siftDown(nums, len(*nums), i)\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\n        siftDown(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) {\n    var i = i\n    while true {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1\n        let r = 2 * i + 2\n        var ma = i\n        if l < n, nums[l] > nums[ma] {\n            ma = l\n        }\n        if r < n, nums[r] > nums[ma] {\n            ma = 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\n        if ma == i {\n            break\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        nums.swapAt(i, ma)\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma\n    }\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\n    for i in stride(from: nums.count / 2 - 1, through: 0, by: -1) {\n        siftDown(nums: &nums, n: nums.count, i: i)\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\n        nums.swapAt(0, i)\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(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) {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1;\n        let r = 2 * i + 2;\n        let ma = i;\n        if (l < n && nums[l] > nums[ma]) {\n            ma = l;\n        }\n        if (r < n && nums[r] > nums[ma]) {\n            ma = 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\n        if (ma === i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        [nums[i], nums[ma]] = [nums[ma], nums[i]];\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\n        siftDown(nums, nums.length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        siftDown(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 {\n    while (true) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1;\n        let r = 2 * i + 2;\n        let ma = i;\n        if (l < n && nums[l] > nums[ma]) {\n            ma = l;\n        }\n        if (r < n && nums[r] > nums[ma]) {\n            ma = 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\n        if (ma === i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        [nums[i], nums[ma]] = [nums[ma], nums[i]];\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (let i = Math.floor(nums.length / 2) - 1; i >= 0; i--) {\n        siftDown(nums, nums.length, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        siftDown(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) {\n  while (true) {\n    // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n    int l = 2 * i + 1;\n    int r = 2 * i + 2;\n    int ma = i;\n    if (l < n && nums[l] > nums[ma]) ma = l;\n    if (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\n    if (ma == i) break;\n    // \u4ea4\u6362\u4e24\u8282\u70b9\n    int temp = nums[i];\n    nums[i] = nums[ma];\n    nums[ma] = temp;\n    // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n    i = ma;\n  }\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\n  for (int i = nums.length ~/ 2 - 1; i >= 0; i--) {\n    siftDown(nums, nums.length, i);\n  }\n  // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n  for (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    int tmp = nums[0];\n    nums[0] = nums[i];\n    nums[i] = tmp;\n    // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n    siftDown(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) {\n    loop {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        let l = 2 * i + 1;\n        let r = 2 * i + 2;\n        let mut ma = i;\n        if l < n && nums[l] > nums[ma] {\n            ma = l;\n        }\n        if r < n && nums[r] > nums[ma] {\n            ma = 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\n        if ma == i {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        let temp = nums[i];\n        nums[i] = nums[ma];\n        nums[ma] = temp;\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for i in (0..=nums.len() / 2 - 1).rev() {\n        sift_down(nums, nums.len(), i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for 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\n        let tmp = nums[0];\n        nums[0] = nums[i];\n        nums[i] = tmp;\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        sift_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) {\n    while (1) {\n        // \u5224\u65ad\u8282\u70b9 i, l, r \u4e2d\u503c\u6700\u5927\u7684\u8282\u70b9\uff0c\u8bb0\u4e3a ma\n        int l = 2 * i + 1;\n        int r = 2 * i + 2;\n        int ma = i;\n        if (l < n && nums[l] > nums[ma])\n            ma = l;\n        if (r < n && nums[r] > nums[ma])\n            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\n        if (ma == i) {\n            break;\n        }\n        // \u4ea4\u6362\u4e24\u8282\u70b9\n        int temp = nums[i];\n        nums[i] = nums[ma];\n        nums[ma] = temp;\n        // \u5faa\u73af\u5411\u4e0b\u5806\u5316\n        i = ma;\n    }\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\n    for (int i = n / 2 - 1; i >= 0; --i) {\n        siftDown(nums, n, i);\n    }\n    // \u4ece\u5806\u4e2d\u63d0\u53d6\u6700\u5927\u5143\u7d20\uff0c\u5faa\u73af n-1 \u8f6e\n    for (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\n        int tmp = nums[0];\n        nums[0] = nums[i];\n        nums[i] = tmp;\n        // \u4ee5\u6839\u8282\u70b9\u4e3a\u8d77\u70b9\uff0c\u4ece\u9876\u81f3\u5e95\u8fdb\u884c\u5806\u5316\n        siftDown(nums, i, 0);\n    }\n}\n
    heap_sort.zig
    [class]{}-[func]{siftDown}\n\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\u4e3a \\(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\u4e3a \\(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]\n    for i in range(1, len(nums)):\n        base = nums[i]\n        j = 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\n        while j >= 0 and nums[j] > base:\n            nums[j + 1] = nums[j]  # \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j -= 1\n        nums[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\n    for (int i = 1; i < nums.size(); i++) {\n        int 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\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n    for (int i = 1; i < nums.length; i++) {\n        int 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\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n    for (int i = 1; i < nums.Length; i++) {\n        int 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\n        while (j >= 0 && nums[j] > bas) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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]\n    for i := 1; i < len(nums); i++ {\n        base := nums[i]\n        j := i - 1\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        for j >= 0 && nums[j] > base {\n            nums[j+1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--\n        }\n        nums[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\n    for i in stride(from: 1, to: nums.count, by: 1) {\n        let base = nums[i]\n        var j = i - 1\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while j >= 0, nums[j] > base {\n            nums[j + 1] = nums[j] // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j -= 1\n        }\n        nums[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\n    for (let i = 1; i < nums.length; i++) {\n        let base = nums[i],\n            j = i - 1;\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n    for (let i = 1; i < nums.length; i++) {\n        const base = nums[i];\n        let j = i - 1;\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while (j >= 0 && nums[j] > base) {\n            nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j--;\n        }\n        nums[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\n  for (int i = 1; i < nums.length; i++) {\n    int 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\n    while (j >= 0 && nums[j] > base) {\n      nums[j + 1] = nums[j]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n      j--;\n    }\n    nums[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\n    for i in 1..nums.len() {\n        let (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\n        while j >= 0 && nums[j as usize] > base {\n            nums[(j + 1) as usize] = nums[j as usize]; // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            j -= 1;\n        }\n        nums[(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\n    for (int i = 1; i < size; i++) {\n        int 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\n        while (j >= 0 && nums[j] > base) {\n            // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n            nums[j + 1] = nums[j];\n            j--;\n        }\n        // \u5c06 base \u8d4b\u503c\u5230\u6b63\u786e\u4f4d\u7f6e\n        nums[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\n    var i: usize = 1;\n    while (i < nums.len) : (i += 1) {\n        var base = nums[i];\n        var j: usize = i;\n        // \u5185\u5faa\u73af\uff1a\u5c06 base \u63d2\u5165\u5230\u5df2\u6392\u5e8f\u90e8\u5206\u7684\u6b63\u786e\u4f4d\u7f6e\n        while (j >= 1 and nums[j - 1] > base) : (j -= 1) {\n            nums[j] = nums[j - 1];  // \u5c06 nums[j] \u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n        }\n        nums[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\u4e3a \\(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\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\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\u7684\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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    # \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    tmp = [0] * (right - left + 1)\n    # \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    i, j, k = left, mid + 1, 0\n    # \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while i <= mid and j <= right:\n        if nums[i] <= nums[j]:\n            tmp[k] = nums[i]\n            i += 1\n        else:\n            tmp[k] = nums[j]\n            j += 1\n        k += 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\n    while i <= mid:\n        tmp[k] = nums[i]\n        i += 1\n        k += 1\n    while j <= right:\n        tmp[k] = nums[j]\n        j += 1\n        k += 1\n    # \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\n    for k in range(0, len(tmp)):\n        nums[left + k] = tmp[k]\n\ndef merge_sort(nums: list[int], left: int, right: int):\n    \"\"\"\u5f52\u5e76\u6392\u5e8f\"\"\"\n    # \u7ec8\u6b62\u6761\u4ef6\n    if left >= right:\n        return  # \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    # \u5212\u5206\u9636\u6bb5\n    mid = (left + right) // 2  # \u8ba1\u7b97\u4e2d\u70b9\n    merge_sort(nums, left, mid)  # \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    merge_sort(nums, mid + 1, right)  # \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    # \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    vector<int> tmp(right - left + 1);\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j])\n            tmp[k++] = nums[i++];\n        else\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.size(); k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(vector<int> &nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right)\n        return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    int[] tmp = new int[right - left + 1];\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j])\n            tmp[k++] = nums[i++];\n        else\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.length; k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int[] nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right)\n        return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2; // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    int[] tmp = new int[right - left + 1];\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j])\n            tmp[k++] = nums[i++];\n        else\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.Length; ++k) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid MergeSort(int[] nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return;       // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\n    MergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    MergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    Merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    tmp := make([]int, right-left+1)\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    i, j, k := left, mid+1, 0\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    for i <= mid && j <= right {\n        if nums[i] <= nums[j] {\n            tmp[k] = nums[i]\n            i++\n        } else {\n            tmp[k] = nums[j]\n            j++\n        }\n        k++\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\n    for i <= mid {\n        tmp[k] = nums[i]\n        i++\n        k++\n    }\n    for j <= right {\n        tmp[k] = nums[j]\n        j++\n        k++\n    }\n    // \u5c06\u4e34\u65f6\u6570\u7ec4 tmp \u4e2d\u7684\u5143\u7d20\u590d\u5236\u56de\u539f\u6570\u7ec4 nums \u7684\u5bf9\u5e94\u533a\u95f4\n    for k := 0; k < len(tmp); k++ {\n        nums[left+k] = tmp[k]\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums []int, left, right int) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if left >= right {\n        return\n    }\n    // \u5212\u5206\u9636\u6bb5\n    mid := (left + right) / 2\n    mergeSort(nums, left, mid)\n    mergeSort(nums, mid+1, right)\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    var 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\n    var i = left, j = mid + 1, k = 0\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while i <= mid, j <= right {\n        if nums[i] <= nums[j] {\n            tmp[k] = nums[i]\n            i += 1\n            k += 1\n        } else {\n            tmp[k] = nums[j]\n            j += 1\n            k += 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\n    while i <= mid {\n        tmp[k] = nums[i]\n        i += 1\n        k += 1\n    }\n    while j <= right {\n        tmp[k] = nums[j]\n        j += 1\n        k += 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\n    for k in tmp.indices {\n        nums[left + k] = tmp[k]\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunc mergeSort(nums: inout [Int], left: Int, right: Int) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if left >= right { // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n        return\n    }\n    // \u5212\u5206\u9636\u6bb5\n    let mid = (left + right) / 2 // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums: &nums, left: left, right: mid) // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums: &nums, left: mid + 1, right: right) // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    const tmp = new Array(right - left + 1);\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    let i = left,\n        j = mid + 1,\n        k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j]) {\n            tmp[k++] = nums[i++];\n        } else {\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.length; k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums, left, right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    let mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    const tmp = new Array(right - left + 1);\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    let i = left,\n        j = mid + 1,\n        k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j]) {\n            tmp[k++] = nums[i++];\n        } else {\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmp.length; k++) {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfunction mergeSort(nums: number[], left: number, right: number): void {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    let mid = Math.floor((left + right) / 2); // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n  // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n  List<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\n  int i = left, j = mid + 1, k = 0;\n  // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n  while (i <= mid && j <= right) {\n    if (nums[i] <= nums[j])\n      tmp[k++] = nums[i++];\n    else\n      tmp[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\n  while (i <= mid) {\n    tmp[k++] = nums[i++];\n  }\n  while (j <= right) {\n    tmp[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\n  for (k = 0; k < tmp.length; k++) {\n    nums[left + k] = tmp[k];\n  }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(List<int> nums, int left, int right) {\n  // \u7ec8\u6b62\u6761\u4ef6\n  if (left >= right) return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n  // \u5212\u5206\u9636\u6bb5\n  int mid = (left + right) ~/ 2; // \u8ba1\u7b97\u4e2d\u70b9\n  mergeSort(nums, left, mid); // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n  mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n  // \u5408\u5e76\u9636\u6bb5\n  merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    let tmp_size = right - left + 1;\n    let mut tmp = vec![0; tmp_size];\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    let (mut i, mut j, mut k) = (left, mid + 1, 0);\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while i <= mid && j <= right {\n        if nums[i] <= nums[j] {\n            tmp[k] = nums[j];\n            i += 1;\n        } else {\n            tmp[k] = nums[j];\n            j += 1;\n        }\n        k += 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\n    while i <= mid {\n        tmp[k] = nums[i];\n        k += 1;\n        i += 1;\n    }\n    while j <= right {\n        tmp[k] = nums[j];\n        k += 1;\n        j += 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\n    for k in 0..tmp_size {\n        nums[left + k] = tmp[k];\n    }\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nfn merge_sort(nums: &mut [i32], left: usize, right: usize) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if left >= right { return; }             // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    let mid = (left + right) / 2;     // \u8ba1\u7b97\u4e2d\u70b9\n    merge_sort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    merge_sort(nums, mid + 1, right);  // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\u4e3a [left, mid], \u53f3\u5b50\u6570\u7ec4\u533a\u95f4\u4e3a [mid+1, right]\n    // \u521b\u5efa\u4e00\u4e2a\u4e34\u65f6\u6570\u7ec4 tmp \uff0c\u7528\u4e8e\u5b58\u653e\u5408\u5e76\u540e\u7684\u7ed3\u679c\n    int tmpSize = right - left + 1;\n    int *tmp = (int *)malloc(tmpSize * sizeof(int));\n    // \u521d\u59cb\u5316\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\n    int i = left, j = mid + 1, k = 0;\n    // \u5f53\u5de6\u53f3\u5b50\u6570\u7ec4\u90fd\u8fd8\u6709\u5143\u7d20\u65f6\uff0c\u8fdb\u884c\u6bd4\u8f83\u5e76\u5c06\u8f83\u5c0f\u7684\u5143\u7d20\u590d\u5236\u5230\u4e34\u65f6\u6570\u7ec4\u4e2d\n    while (i <= mid && j <= right) {\n        if (nums[i] <= nums[j]) {\n            tmp[k++] = nums[i++];\n        } else {\n            tmp[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\n    while (i <= mid) {\n        tmp[k++] = nums[i++];\n    }\n    while (j <= right) {\n        tmp[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\n    for (k = 0; k < tmpSize; ++k) {\n        nums[left + k] = tmp[k];\n    }\n    // \u91ca\u653e\u5185\u5b58\n    free(tmp);\n}\n\n/* \u5f52\u5e76\u6392\u5e8f */\nvoid mergeSort(int *nums, int left, int right) {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right)\n        return; // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    int mid = (left + right) / 2;    // \u8ba1\u7b97\u4e2d\u70b9\n    mergeSort(nums, left, mid);      // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    mergeSort(nums, mid + 1, right); // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    merge(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\n    var mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n    defer mem_arena.deinit();\n    const mem_allocator = mem_arena.allocator();\n    var tmp = try mem_allocator.alloc(i32, right + 1 - left);\n    std.mem.copy(i32, tmp, nums[left..right+1]);\n    // \u5de6\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15  \n    var leftStart = left - left;\n    var leftEnd = mid - left;\n    // \u53f3\u5b50\u6570\u7ec4\u7684\u8d77\u59cb\u7d22\u5f15\u548c\u7ed3\u675f\u7d22\u5f15       \n    var rightStart = mid + 1 - left;\n    var rightEnd = right - left;\n    // i, j \u5206\u522b\u6307\u5411\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\u7684\u9996\u5143\u7d20\n    var i = leftStart;\n    var j = rightStart;\n    // \u901a\u8fc7\u8986\u76d6\u539f\u6570\u7ec4 nums \u6765\u5408\u5e76\u5de6\u5b50\u6570\u7ec4\u548c\u53f3\u5b50\u6570\u7ec4\n    var k = left;\n    while (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++\n        if (i > leftEnd) {\n            nums[k] = tmp[j];\n            j += 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]) {\n            nums[k] = tmp[i];\n            i += 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 {\n            nums[k] = tmp[j];\n            j += 1;\n        }\n    }\n}\n\n// \u5f52\u5e76\u6392\u5e8f\nfn mergeSort(nums: []i32, left: usize, right: usize) !void {\n    // \u7ec8\u6b62\u6761\u4ef6\n    if (left >= right) return;              // \u5f53\u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    // \u5212\u5206\u9636\u6bb5\n    var mid = (left + right) / 2;           // \u8ba1\u7b97\u4e2d\u70b9\n    try mergeSort(nums, left, mid);         // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\n    try mergeSort(nums, mid + 1, right);    // \u9012\u5f52\u53f3\u5b50\u6570\u7ec4\n    // \u5408\u5e76\u9636\u6bb5\n    try 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\u4e3a \\(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\u4e3a \\(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\n    i, j = left, right\n    while i < j:\n        while i < j and nums[j] >= nums[left]:\n            j -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while i < j and nums[i] <= nums[left]:\n            i += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        # \u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    # \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return 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) {\n    int tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nint partition(vector<int> &nums, int left, int right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return 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) {\n    int tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nint partition(int[] nums, int left, int right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return 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\n/* \u54e8\u5175\u5212\u5206 */\nint Partition(int[] nums, int left, int right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return 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\n    i, j := left, right\n    for i < j {\n        for i < j && nums[j] >= nums[left] {\n            j-- // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        for i < j && nums[i] <= nums[left] {\n            i++ // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        // \u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    }\n    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return 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) {\n    let tmp = nums[i]\n    nums[i] = nums[j]\n    nums[j] = tmp\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nfunc partition(nums: inout [Int], left: Int, right: Int) -> Int {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    var i = left\n    var j = right\n    while i < j {\n        while i < j, nums[j] >= nums[left] {\n            j -= 1 // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while i < j, nums[i] <= nums[left] {\n            i += 1 // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        swap(nums: &nums, i: i, j: j) // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    swap(nums: &nums, i: i, j: left) // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return i // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.js
    /* \u5143\u7d20\u4ea4\u6362 */\nswap(nums, i, j) {\n    let tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums, left, right) {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        // \u5143\u7d20\u4ea4\u6362\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return 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 {\n    let tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\npartition(nums: number[], left: number, right: number): number {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            i += 1; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        // \u5143\u7d20\u4ea4\u6362\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return 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) {\n  int tmp = nums[i];\n  nums[i] = nums[j];\n  nums[j] = tmp;\n}\n\n/* \u54e8\u5175\u5212\u5206 */\nint _partition(List<int> nums, int left, int right) {\n  // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n  int i = left, j = right;\n  while (i < j) {\n    while (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n    while (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\n  return 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\n    let (mut i, mut j) = (left, right);\n    while i < j {\n        while i < j && nums[j] >= nums[left] {\n            j -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while i < j && nums[i] <= nums[left] {\n            i += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        nums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    nums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    i                    // \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) {\n    int tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            j--;\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            i++;\n        }\n        // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n        swap(nums, i, j);\n    }\n    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    swap(nums, i, left);\n    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n    return i;\n}\n
    quick_sort.zig
    // \u5143\u7d20\u4ea4\u6362\nfn swap(nums: []i32, i: usize, j: usize) void {\n    var tmp = nums[i];\n    nums[i] = nums[j];\n    nums[j] = tmp;\n}\n\n// \u54e8\u5175\u5212\u5206\nfn partition(nums: []i32, left: usize, right: usize) usize {\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    var i = left;\n    var j = right;\n    while (i < j) {\n        while (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j and nums[i] <= nums[left]) i += 1; // \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\n    return 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\n    if left >= right:\n        return\n    # \u54e8\u5175\u5212\u5206\n    pivot = self.partition(nums, left, right)\n    # \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    self.quick_sort(nums, left, pivot - 1)\n    self.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\n    if (left >= right)\n        return;\n    // \u54e8\u5175\u5212\u5206\n    int pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\n    if (left >= right)\n        return;\n    // \u54e8\u5175\u5212\u5206\n    int pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\n    if (left >= right)\n        return;\n    // \u54e8\u5175\u5212\u5206\n    int pivot = Partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    QuickSort(nums, left, pivot - 1);\n    QuickSort(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\n    if left >= right {\n        return\n    }\n    // \u54e8\u5175\u5212\u5206\n    pivot := q.partition(nums, left, right)\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    q.quickSort(nums, left, pivot-1)\n    q.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\n    if left >= right {\n        return\n    }\n    // \u54e8\u5175\u5212\u5206\n    let pivot = partition(nums: &nums, left: left, right: right)\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums: &nums, left: left, right: pivot - 1)\n    quickSort(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\n    if (left >= right) return;\n    // \u54e8\u5175\u5212\u5206\n    const pivot = this.partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    this.quickSort(nums, left, pivot - 1);\n    this.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\n    if (left >= right) {\n        return;\n    }\n    // \u54e8\u5175\u5212\u5206\n    const pivot = this.partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    this.quickSort(nums, left, pivot - 1);\n    this.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\n  if (left >= right) return;\n  // \u54e8\u5175\u5212\u5206\n  int pivot = _partition(nums, left, right);\n  // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n  quickSort(nums, left, pivot - 1);\n  quickSort(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\n    if left >= right {\n        return;\n    }\n    // \u54e8\u5175\u5212\u5206\n    let pivot = Self::partition(nums, left as usize, right as usize) as i32;\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    Self::quick_sort(left, pivot - 1, nums);\n    Self::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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            j--;\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n            i++;\n        }\n        // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n        swap(nums, i, j);\n    }\n    // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    swap(nums, i, left);\n    // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n    return i;\n}\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\n    if (left >= right) {\n        return;\n    }\n    // \u54e8\u5175\u5212\u5206\n    int pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\n    if (left >= right) return;\n    // \u54e8\u5175\u5212\u5206\n    var pivot = partition(nums, left, right);\n    // \u9012\u5f52\u5de6\u5b50\u6570\u7ec4\u3001\u53f3\u5b50\u6570\u7ec4\n    quickSort(nums, left, pivot - 1);\n    quickSort(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\u4e3a \\(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\u4e3a \\(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\u5019\u9009\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\n    if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]):\n        return left\n    elif (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]):\n        return mid\n    return right\n\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\n    med = self.median_three(nums, left, (left + right) // 2, right)\n    # \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    nums[left], nums[med] = nums[med], nums[left]\n    # \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    i, j = left, right\n    while i < j:\n        while i < j and nums[j] >= nums[left]:\n            j -= 1  # \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while i < j and nums[i] <= nums[left]:\n            i += 1  # \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        # \u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    # \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return i  # \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n
    quick_sort.cpp
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\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\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.java
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\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\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.cs
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\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\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--;          // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;             // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.go
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\n        return left\n    } else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\n        return mid\n    }\n    return right\n}\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\n    med := q.medianThree(nums, left, (left+right)/2, right)\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    nums[left], nums[med] = nums[med], nums[left]\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    i, j := left, right\n    for i < j {\n        for i < j && nums[j] >= nums[left] {\n            j-- //\u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        for i < j && nums[i] <= nums[left] {\n            i++ //\u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        //\u5143\u7d20\u4ea4\u6362\n        nums[i], nums[j] = nums[j], nums[i]\n    }\n    //\u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    nums[i], nums[left] = nums[left], nums[i]\n    return i //\u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.swift
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nfunc medianThree(nums: [Int], left: Int, mid: Int, right: Int) -> Int {\n    if (nums[left] < nums[mid]) != (nums[left] < nums[right]) {\n        return left\n    } else if (nums[mid] < nums[left]) != (nums[mid] < nums[right]) {\n        return mid\n    } else {\n        return right\n    }\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\n    let 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\n    swap(nums: &nums, i: left, j: med)\n    return partition(nums: &nums, left: left, right: right)\n}\n
    quick_sort.js
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right])) return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else return right;\n}\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\n    let med = this.medianThree(\n        nums,\n        left,\n        Math.floor((left + right) / 2),\n        right\n    );\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    this.swap(nums, left, med);\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left]) i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.ts
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570 */\nmedianThree(\n    nums: number[],\n    left: number,\n    mid: number,\n    right: 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\n    if (Number(nums[left] < nums[mid]) ^ Number(nums[left] < nums[right])) {\n        return left;\n    } else if (\n        Number(nums[mid] < nums[left]) ^ Number(nums[mid] < nums[right])\n    ) {\n        return mid;\n    } else {\n        return right;\n    }\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\n    let med = this.medianThree(\n        nums,\n        left,\n        Math.floor((left + right) / 2),\n        right\n    );\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    this.swap(nums, left, med);\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let i = left,\n        j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left]) {\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while (i < j && nums[i] <= nums[left]) {\n            i++; // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        this.swap(nums, i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n    this.swap(nums, i, left); // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n    return i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.dart
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n  if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n    return left;\n  else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n    return mid;\n  else\n    return right;\n}\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\n  int 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\n  int i = left, j = right;\n  while (i < j) {\n    while (i < j && nums[j] >= nums[left]) j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n    while (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\n  return i; // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.rs
    /* \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if (nums[left] < nums[mid]) ^ (nums[left] < nums[right]) {\n        return left;\n    } else if (nums[mid] < nums[left]) ^ (nums[mid] < nums[right]) {\n        return mid;\n    } \n    right\n}\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\n    let med = Self::median_three(nums, left, (left + right) / 2, right);\n    // \u5c06\u4e2d\u4f4d\u6570\u4ea4\u6362\u81f3\u6570\u7ec4\u6700\u5de6\u7aef\n    nums.swap(left, med);\n    // \u4ee5 nums[left] \u4e3a\u57fa\u51c6\u6570\n    let (mut i, mut j) = (left, right);\n    while i < j {\n        while i < j && nums[j] >= nums[left] {\n            j -= 1;      // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        while i < j && nums[i] <= nums[left] {\n            i += 1;      // \u4ece\u5de6\u5411\u53f3\u627e\u9996\u4e2a\u5927\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        }\n        nums.swap(i, j); // \u4ea4\u6362\u8fd9\u4e24\u4e2a\u5143\u7d20\n    }\n     nums.swap(i, left);  // \u5c06\u57fa\u51c6\u6570\u4ea4\u6362\u81f3\u4e24\u5b50\u6570\u7ec4\u7684\u5206\u754c\u7ebf\n     i                    // \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\u5019\u9009\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\n    if ((nums[left] < nums[mid]) ^ (nums[left] < nums[right]))\n        return left;\n    else if ((nums[mid] < nums[left]) ^ (nums[mid] < nums[right]))\n        return mid;\n    else\n        return right;\n}\n\n/* \u54e8\u5175\u5212\u5206\uff08\u4e09\u6570\u53d6\u4e2d\u503c\uff09 */ \nint partitionMedian(int nums[], int left, int right) {\n    // \u9009\u53d6\u4e09\u4e2a\u5019\u9009\u5143\u7d20\u7684\u4e2d\u4f4d\u6570\n    int 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\n    int i = left, j = right;\n    while (i < j) {\n        while (i < j && nums[j] >= nums[left])\n            j--; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j && nums[i] <= nums[left])\n            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\n    return i;            // \u8fd4\u56de\u57fa\u51c6\u6570\u7684\u7d22\u5f15\n}\n
    quick_sort.zig
    // \u9009\u53d6\u4e09\u4e2a\u5019\u9009\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\n    if ((nums[left] < nums[mid]) != (nums[left] < nums[right])) {\n        return left;\n    } else if ((nums[mid] < nums[left]) != (nums[mid] < nums[right])) {\n        return mid;\n    } else {\n        return right;\n    }\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\n    var 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\n    var i = left;\n    var j = right;\n    while (i < j) {\n        while (i < j and nums[j] >= nums[left]) j -= 1; // \u4ece\u53f3\u5411\u5de6\u627e\u9996\u4e2a\u5c0f\u4e8e\u57fa\u51c6\u6570\u7684\u5143\u7d20\n        while (i < j and nums[i] <= nums[left]) i += 1; // \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\n    return 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\u6709\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\n    while left < right:\n        # \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        pivot = self.partition(nums, left, right)\n        # \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if pivot - left < right - pivot:\n            self.quick_sort(nums, left, pivot - 1)  # \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1  # \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        else:\n            self.quick_sort(nums, pivot + 1, right)  # \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = Partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            QuickSort(nums, left, pivot - 1);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            QuickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    for left < right {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        pivot := q.partition(nums, left, right)\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if pivot-left < right-pivot {\n            q.quickSort(nums, left, pivot-1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1                 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            q.quickSort(nums, pivot+1, right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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) {\n    var left = left\n    var right = right\n    // \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\n    while left < right {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if (pivot - left) < (right - pivot) {\n            quickSortTailCall(nums: &nums, left: left, right: pivot - 1) // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1 // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSortTailCall(nums: &nums, left: pivot + 1, right: right) // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if (pivot - left < right - pivot) {\n            this.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            this.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if (pivot - left < right - pivot) {\n            this.quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            this.quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n  while (left < right) {\n    // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n    int pivot = _partition(nums, left, right);\n    // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n    if (pivot - left < right - pivot) {\n      quickSort(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n      left = pivot + 1; // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n    } else {\n      quickSort(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n      right = 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\n    while left < right {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        let 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\n        if  pivot - left < right - pivot {\n            Self::quick_sort(left, pivot - 1, nums);  // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;  // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            Self::quick_sort(pivot + 1, right, nums); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        int pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSortTailCall(nums, left, pivot - 1); // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;                         // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSortTailCall(nums, pivot + 1, right); // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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 {\n    var left = left_;\n    var right = right_;\n    // \u5b50\u6570\u7ec4\u957f\u5ea6\u4e3a 1 \u65f6\u7ec8\u6b62\u9012\u5f52\n    while (left < right) {\n        // \u54e8\u5175\u5212\u5206\u64cd\u4f5c\n        var pivot = partition(nums, left, right);\n        // \u5bf9\u4e24\u4e2a\u5b50\u6570\u7ec4\u4e2d\u8f83\u77ed\u7684\u90a3\u4e2a\u6267\u884c\u5feb\u901f\u6392\u5e8f\n        if (pivot - left < right - pivot) {\n            quickSort(nums, left, pivot - 1);   // \u9012\u5f52\u6392\u5e8f\u5de6\u5b50\u6570\u7ec4\n            left = pivot + 1;                   // \u5269\u4f59\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [pivot + 1, right]\n        } else {\n            quickSort(nums, pivot + 1, right);  // \u9012\u5f52\u6392\u5e8f\u53f3\u5b50\u6570\u7ec4\n            right = 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\u6a21\uff08\u53d6\u4f59\uff09\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\n    return (num // exp) % 10\n\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\n    counter = [0] * 10\n    n = len(nums)\n    # \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i in range(n):\n        d = digit(nums[i], exp)  # \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i in range(1, 10):\n        counter[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\n    res = [0] * n\n    for i in range(n - 1, -1, -1):\n        d = digit(nums[i], exp)\n        j = counter[d] - 1  # \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]  # \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1  # \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    # \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i in range(n):\n        nums[i] = res[i]\n\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\n    m = max(nums)\n    # \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    exp = 1\n    while 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)\n        counting_sort_digit(nums, exp)\n        exp *= 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\n    return (num / exp) % 10;\n}\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\n    vector<int> counter(10, 0);\n    int n = nums.size();\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < n; i++) {\n        int d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    vector<int> res(n, 0);\n    for (int i = n - 1; i >= 0; i--) {\n        int d = digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < n; i++)\n        nums[i] = res[i];\n}\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\n    int m = *max_element(nums.begin(), nums.end());\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return (num / exp) % 10;\n}\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\n    int[] counter = new int[10];\n    int n = nums.length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < n; i++) {\n        int d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int d = digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < n; i++)\n        nums[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\n    int m = Integer.MIN_VALUE;\n    for (int num : nums)\n        if (num > m)\n            m = num;\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return (num / exp) % 10;\n}\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\n    int[] counter = new int[10];\n    int n = nums.Length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < n; i++) {\n        int d = Digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    int[] res = new int[n];\n    for (int i = n - 1; i >= 0; i--) {\n        int d = Digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < n; i++) {\n        nums[i] = res[i];\n    }\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\n    int m = int.MinValue;\n    foreach (int num in nums) {\n        if (num > m) m = num;\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        CountingSortDigit(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\n    return (num / exp) % 10\n}\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\n    counter := make([]int, 10)\n    n := len(nums)\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i := 0; i < n; i++ {\n        d := digit(nums[i], exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i := 1; i < 10; i++ {\n        counter[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\n    res := make([]int, n)\n    for i := n - 1; i >= 0; i-- {\n        d := digit(nums[i], exp)\n        j := counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]    // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i := 0; i < n; i++ {\n        nums[i] = res[i]\n    }\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\n    max := math.MinInt\n    for _, num := range nums {\n        if num > max {\n            max = num\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for 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)\n        countingSortDigit(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\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\n    var counter = Array(repeating: 0, count: 10)\n    let n = nums.count\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i in nums.indices {\n        let d = digit(num: nums[i], exp: exp) // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i in 1 ..< 10 {\n        counter[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\n    var res = Array(repeating: 0, count: n)\n    for i in stride(from: n - 1, through: 0, by: -1) {\n        let d = digit(num: nums[i], exp: exp)\n        let j = counter[d] - 1 // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i] // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1 // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i in nums.indices {\n        nums[i] = res[i]\n    }\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\n    var m = Int.min\n    for num in nums {\n        if num > m {\n            m = num\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for 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)\n        countingSortDigit(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\n    return Math.floor(num / exp) % 10;\n}\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\n    const counter = new Array(10).fill(0);\n    const n = nums.length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (let i = 0; i < n; i++) {\n        const d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (let i = 1; i < 10; i++) {\n        counter[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\n    const res = new Array(n).fill(0);\n    for (let i = n - 1; i >= 0; i--) {\n        const d = digit(nums[i], exp);\n        const j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (let i = 0; i < n; i++) {\n        nums[i] = res[i];\n    }\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\n    let m = Number.MIN_VALUE;\n    for (const num of nums) {\n        if (num > m) {\n            m = num;\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return Math.floor(num / exp) % 10;\n}\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\n    const counter = new Array(10).fill(0);\n    const n = nums.length;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (let i = 0; i < n; i++) {\n        const d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for (let i = 1; i < 10; i++) {\n        counter[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\n    const res = new Array(n).fill(0);\n    for (let i = n - 1; i >= 0; i--) {\n        const d = digit(nums[i], exp);\n        const j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (let i = 0; i < n; i++) {\n        nums[i] = res[i];\n    }\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\n    let m = Number.MIN_VALUE;\n    for (const num of nums) {\n        if (num > m) {\n            m = num;\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n  return (_num ~/ exp) % 10;\n}\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\n  List<int> counter = List<int>.filled(10, 0);\n  int n = nums.length;\n  // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n  for (int i = 0; i < n; i++) {\n    int d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n    counter[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\n  for (int i = 1; i < 10; i++) {\n    counter[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\n  List<int> res = List<int>.filled(n, 0);\n  for (int i = n - 1; i >= 0; i--) {\n    int d = digit(nums[i], exp);\n    int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n    res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n    counter[d]--; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n  }\n  // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n  for (int i = 0; i < n; i++) nums[i] = res[i];\n}\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\n  int m = -1 << 63;\n  for (int _num in nums) if (_num > m) m = _num;\n  // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n  for (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)\n    countingSortDigit(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\n    return ((num / exp) % 10) as usize;\n}\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\n    let mut counter = [0; 10];\n    let n = nums.len();\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for i in 0..n {\n        let d = digit(nums[i], exp); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    for i in 1..10 {\n        counter[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\n    let mut res = vec![0; n];\n    for i in (0..n).rev() {\n        let d = digit(nums[i], exp);\n        let j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i]; // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1; // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for i in 0..n {\n        nums[i] = res[i];\n    }\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\n    let m = *nums.into_iter().max().unwrap();\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    let mut exp = 1;\n    while exp <= m {\n        counting_sort_digit(nums, exp);\n        exp *= 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\n    return (num / exp) % 10;\n}\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\n    int *counter = (int *)malloc((sizeof(int) * 10));\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (int i = 0; i < size; i++) {\n        // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        int d = digit(nums[i], exp);\n        // \u7edf\u8ba1\u6570\u5b57 d \u7684\u51fa\u73b0\u6b21\u6570\n        counter[d]++;\n    }\n    // \u6c42\u524d\u7f00\u548c\uff0c\u5c06\u201c\u51fa\u73b0\u4e2a\u6570\u201d\u8f6c\u6362\u4e3a\u201c\u6570\u7ec4\u7d22\u5f15\u201d\n    for (int i = 1; i < 10; i++) {\n        counter[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\n    int *res = (int *)malloc(sizeof(int) * size);\n    for (int i = size - 1; i >= 0; i--) {\n        int d = digit(nums[i], exp);\n        int j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d]--;           // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    for (int i = 0; i < size; i++) {\n        nums[i] = res[i];\n    }\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\n    int max = INT32_MIN;\n    for (size_t i = 0; i < size - 1; i++) {\n        if (nums[i] > max) {\n            max = nums[i];\n        }\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    for (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)\n        countingSortDigit(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\n    return @mod(@divFloor(num, exp), 10);\n}\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\n    var mem_arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);\n    // defer mem_arena.deinit();\n    const mem_allocator = mem_arena.allocator();\n    var counter = try mem_allocator.alloc(usize, 10);\n    @memset(counter, 0);\n    var n = nums.len;\n    // \u7edf\u8ba1 0~9 \u5404\u6570\u5b57\u7684\u51fa\u73b0\u6b21\u6570\n    for (nums) |num| {\n        var d: u32 = @bitCast(digit(num, exp)); // \u83b7\u53d6 nums[i] \u7b2c k \u4f4d\uff0c\u8bb0\u4e3a d\n        counter[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\n    var i: usize = 1;\n    while (i < 10) : (i += 1) {\n        counter[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\n    var res = try mem_allocator.alloc(i32, n);\n    i = n - 1;\n    while (i >= 0) : (i -= 1) {\n        var d: u32 = @bitCast(digit(nums[i], exp));\n        var j = counter[d] - 1; // \u83b7\u53d6 d \u5728\u6570\u7ec4\u4e2d\u7684\u7d22\u5f15 j\n        res[j] = nums[i];       // \u5c06\u5f53\u524d\u5143\u7d20\u586b\u5165\u7d22\u5f15 j\n        counter[d] -= 1;        // \u5c06 d \u7684\u6570\u91cf\u51cf 1\n        if (i == 0) break;\n    }\n    // \u4f7f\u7528\u7ed3\u679c\u8986\u76d6\u539f\u6570\u7ec4 nums\n    i = 0;\n    while (i < n) : (i += 1) {\n        nums[i] = res[i];\n    }\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\n    var m: i32 = std.math.minInt(i32);\n    for (nums) |num| {\n        if (num > m) m = num;\n    }\n    // \u6309\u7167\u4ece\u4f4e\u4f4d\u5230\u9ad8\u4f4d\u7684\u987a\u5e8f\u904d\u5386\n    var exp: i32 = 1;\n    while (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)\n        try countingSortDigit(nums, exp);    \n    }\n} \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\u4e3a \\(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\u4e3a \\(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\u5f53\u8ba1\u6570\u6392\u5e8f\u7a33\u5b9a\u65f6\uff0c\u57fa\u6570\u6392\u5e8f\u4e5f\u7a33\u5b9a\uff1b\u5f53\u8ba1\u6570\u6392\u5e8f\u4e0d\u7a33\u5b9a\u65f6\uff0c\u57fa\u6570\u6392\u5e8f\u65e0\u6cd5\u4fdd\u8bc1\u5f97\u5230\u6b63\u786e\u7684\u6392\u5e8f\u7ed3\u679c\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\"\"\"\n    n = len(nums)\n    # \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for i in range(n - 1):\n        # \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        k = i\n        for j in range(i + 1, n):\n            if nums[j] < nums[k]:\n                k = 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\n        nums[i], nums[k] = nums[k], nums[i]\n
    selection_sort.cpp
    /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(vector<int> &nums) {\n    int n = nums.size();\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        swap(nums[i], nums[k]);\n    }\n}\n
    selection_sort.java
    /* \u9009\u62e9\u6392\u5e8f */\nvoid selectionSort(int[] nums) {\n    int n = nums.length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        int temp = nums[i];\n        nums[i] = nums[k];\n        nums[k] = temp;\n    }\n}\n
    selection_sort.cs
    /* \u9009\u62e9\u6392\u5e8f */\nvoid SelectionSort(int[] nums) {\n    int n = nums.Length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        (nums[k], nums[i]) = (nums[i], nums[k]);\n    }\n}\n
    selection_sort.go
    /* \u9009\u62e9\u6392\u5e8f */\nfunc selectionSort(nums []int) {\n    n := len(nums)\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for i := 0; i < n-1; i++ {\n        // \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        k := i\n        for j := i + 1; j < n; j++ {\n            if nums[j] < nums[k] {\n                // \u8bb0\u5f55\u6700\u5c0f\u5143\u7d20\u7684\u7d22\u5f15\n                k = j\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}\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]\n    for i in nums.indices.dropLast() {\n        // \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        var k = i\n        for j in nums.indices.dropFirst(i + 1) {\n            if nums[j] < nums[k] {\n                k = 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.swapAt(i, k)\n    }\n}\n
    selection_sort.js
    /* \u9009\u62e9\u6392\u5e8f */\nfunction selectionSort(nums) {\n    let n = nums.length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        let k = i;\n        for (let j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k]) {\n                k = 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 {\n    let n = nums.length;\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for (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\n        let k = i;\n        for (let j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k]) {\n                k = 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) {\n  int n = nums.length;\n  // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n  for (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\n    int k = i;\n    for (int j = i + 1; j < n; j++) {\n      if (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\n    int temp = nums[i];\n    nums[i] = nums[k];\n    nums[k] = temp;\n  }\n}\n
    selection_sort.rs
    /* \u9009\u62e9\u6392\u5e8f */\nfn selection_sort(nums: &mut [i32]) {\n    let n = nums.len();\n    // \u5916\u5faa\u73af\uff1a\u672a\u6392\u5e8f\u533a\u95f4\u4e3a [i, n-1]\n    for i in 0..n-1 {\n        // \u5185\u5faa\u73af\uff1a\u627e\u5230\u672a\u6392\u5e8f\u533a\u95f4\u5185\u7684\u6700\u5c0f\u5143\u7d20\n        let mut k = i;\n        for j in i+1..n {\n            if nums[j] < nums[k] {\n                k = 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.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]\n    for (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\n        int k = i;\n        for (int j = i + 1; j < n; j++) {\n            if (nums[j] < nums[k])\n                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\n        int temp = nums[i];\n        nums[i] = nums[k];\n        nums[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\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
    • \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\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\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\u5927\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\n# \u521d\u59cb\u5316\u53cc\u5411\u961f\u5217\ndeque: deque[int] = deque()\n\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\n# \u8bbf\u95ee\u5143\u7d20\nfront: int = deque[0]  # \u961f\u9996\u5143\u7d20\nrear: int = deque[-1]  # \u961f\u5c3e\u5143\u7d20\n\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\n# \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(deque)\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint front = deque.front(); // \u961f\u9996\u5143\u7d20\nint back = deque.back();   // \u961f\u5c3e\u5143\u7d20\n\n/* \u5143\u7d20\u51fa\u961f */\ndeque.pop_front();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.pop_back();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.peekFirst();  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.peekLast();    // \u961f\u5c3e\u5143\u7d20\n\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.size();\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.First.Value;  // \u961f\u9996\u5143\u7d20\nint peekLast = deque.Last.Value;    // \u961f\u5c3e\u5143\u7d20\n\n/* \u5143\u7d20\u51fa\u961f */\ndeque.RemoveFirst();  // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.RemoveLast();   // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.Count;\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nfront := deque.Front() // \u961f\u9996\u5143\u7d20\nrear := deque.Back()   // \u961f\u5c3e\u5143\u7d20\n\n/* \u5143\u7d20\u51fa\u961f */\ndeque.Remove(front)    // \u961f\u9996\u5143\u7d20\u51fa\u961f\ndeque.Remove(rear)     // \u961f\u5c3e\u5143\u7d20\u51fa\u961f\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nsize := deque.Len()\n\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nlet peekFirst = deque.first! // \u961f\u9996\u5143\u7d20\nlet peekLast = deque.last! // \u961f\u5c3e\u5143\u7d20\n\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.count\n\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\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\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\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\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\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\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\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\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\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\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\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\n/* \u8bbf\u95ee\u5143\u7d20 */\nint peekFirst = deque.first; // \u961f\u9996\u5143\u7d20\nint peekLast = deque.last;   // \u961f\u5c3e\u5143\u7d20\n\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size = deque.length;\n\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\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\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\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\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n\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\"\"\"\n\n    def __init__(self, val: int):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self.val: int = val\n        self.next: ListNode | None = None  # \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n        self.prev: ListNode | None = None  # \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\nclass LinkedListDeque:\n    \"\"\"\u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._front: ListNode | None = None  # \u5934\u8282\u70b9 front\n        self._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\n        self._size: int = 0  # \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self.size() == 0\n\n    def push(self, num: int, is_front: bool):\n        \"\"\"\u5165\u961f\u64cd\u4f5c\"\"\"\n        node = ListNode(num)\n        # \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if self.is_empty():\n            self._front = self._rear = node\n        # \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        elif is_front:\n            # \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            self._front.prev = node\n            node.next = self._front\n            self._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\n            self._rear.next = node\n            node.prev = self._rear\n            self._rear = node  # \u66f4\u65b0\u5c3e\u8282\u70b9\n        self._size += 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n\n    def push_first(self, num: int):\n        \"\"\"\u961f\u9996\u5165\u961f\"\"\"\n        self.push(num, True)\n\n    def push_last(self, num: int):\n        \"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\n        self.push(num, False)\n\n    def pop(self, is_front: bool) -> int:\n        \"\"\"\u51fa\u961f\u64cd\u4f5c\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        # \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if is_front:\n            val: int = self._front.val  # \u6682\u5b58\u5934\u8282\u70b9\u503c\n            # \u5220\u9664\u5934\u8282\u70b9\n            fnext: ListNode | None = self._front.next\n            if fnext != None:\n                fnext.prev = None\n                self._front.next = None\n            self._front = fnext  # \u66f4\u65b0\u5934\u8282\u70b9\n        # \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else:\n            val: int = self._rear.val  # \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            # \u5220\u9664\u5c3e\u8282\u70b9\n            rprev: ListNode | None = self._rear.prev\n            if rprev != None:\n                rprev.next = None\n                self._rear.prev = None\n            self._rear = rprev  # \u66f4\u65b0\u5c3e\u8282\u70b9\n        self._size -= 1  # \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val\n\n    def pop_first(self) -> int:\n        \"\"\"\u961f\u9996\u51fa\u961f\"\"\"\n        return self.pop(True)\n\n    def pop_last(self) -> int:\n        \"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\n        return self.pop(False)\n\n    def peek_first(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        return self._front.val\n\n    def peek_last(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        return self._rear.val\n\n    def to_array(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\"\"\"\n        node = self._front\n        res = [0] * self.size()\n        for i in range(self.size()):\n            res[i] = node.val\n            node = node.next\n        return res\n
    linkedlist_deque.cpp
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nstruct DoublyListNode {\n    int val;              // \u8282\u70b9\u503c\n    DoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\u6307\u9488\n    DoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\u6307\u9488\n    DoublyListNode(int val) : val(val), prev(nullptr), next(nullptr) {\n    }\n};\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n  private:\n    DoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    int queSize = 0;              // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    LinkedListDeque() : front(nullptr), rear(nullptr) {\n    }\n\n    /* \u6790\u6784\u65b9\u6cd5 */\n    ~LinkedListDeque() {\n        // \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n        DoublyListNode *pre, *cur = front;\n        while (cur != nullptr) {\n            pre = cur;\n            cur = cur->next;\n            delete pre;\n        }\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    void push(int num, bool isFront) {\n        DoublyListNode *node = new DoublyListNode(num);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (isEmpty())\n            front = rear = node;\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if (isFront) {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front->prev = node;\n            node->next = front;\n            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\n            rear->next = node;\n            node->prev = rear;\n            rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    void pushFirst(int num) {\n        push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    void pushLast(int num) {\n        push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    int pop(bool isFront) {\n        if (isEmpty())\n            throw out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\n        int val;\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if (isFront) {\n            val = front->val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            DoublyListNode *fNext = front->next;\n            if (fNext != nullptr) {\n                fNext->prev = nullptr;\n                front->next = nullptr;\n                delete front;\n            }\n            front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        } else {\n            val = rear->val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            DoublyListNode *rPrev = rear->prev;\n            if (rPrev != nullptr) {\n                rPrev->next = nullptr;\n                rear->prev = nullptr;\n                delete rear;\n            }\n            rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    int popFirst() {\n        return pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    int popLast() {\n        return pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peekFirst() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        return front->val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    int peekLast() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        return rear->val;\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    vector<int> toVector() {\n        DoublyListNode *node = front;\n        vector<int> res(size());\n        for (int i = 0; i < res.size(); i++) {\n            res[i] = node->val;\n            node = node->next;\n        }\n        return res;\n    }\n};\n
    linkedlist_deque.java
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    int val; // \u8282\u70b9\u503c\n    ListNode next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n    ListNode prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\n    ListNode(int val) {\n        this.val = val;\n        prev = next = null;\n    }\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    private ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    private int queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    public LinkedListDeque() {\n        front = rear = null;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    private void push(int num, boolean isFront) {\n        ListNode node = new ListNode(num);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (isEmpty())\n            front = rear = node;\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if (isFront) {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front.prev = node;\n            node.next = front;\n            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\n            rear.next = node;\n            node.prev = rear;\n            rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void pushFirst(int num) {\n        push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    public void pushLast(int num) {\n        push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    private int pop(boolean isFront) {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        int val;\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if (isFront) {\n            val = front.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            ListNode fNext = front.next;\n            if (fNext != null) {\n                fNext.prev = null;\n                front.next = null;\n            }\n            front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        } else {\n            val = rear.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            ListNode rPrev = rear.prev;\n            if (rPrev != null) {\n                rPrev.next = null;\n                rear.prev = null;\n            }\n            rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int popFirst() {\n        return pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int popLast() {\n        return pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peekFirst() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return front.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int peekLast() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return rear.val;\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int[] toArray() {\n        ListNode node = front;\n        int[] res = new int[size()];\n        for (int i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_deque.cs
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode(int val) {\n    public int val = val;       // \u8282\u70b9\u503c\n    public ListNode? next = null; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n    public ListNode? prev = null; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    ListNode? front, rear; // \u5934\u8282\u70b9 front, \u5c3e\u8282\u70b9 rear\n    int queSize = 0;      // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    public LinkedListDeque() {\n        front = null;\n        rear = null;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    void Push(int num, bool isFront) {\n        ListNode node = new(num);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (IsEmpty()) {\n            front = node;\n            rear = node;\n        }\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if (isFront) {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front!.prev = node;\n            node.next = front;\n            front = node; // \u66f4\u65b0\u5934\u8282\u70b9                           \n        }\n        // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n        else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            rear!.next = node;\n            node.prev = rear;\n            rear = node;  // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n\n        queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void PushFirst(int num) {\n        Push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    public void PushLast(int num) {\n        Push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    int? Pop(bool isFront) {\n        if (IsEmpty())\n            throw new Exception();\n        int? val;\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if (isFront) {\n            val = front?.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            ListNode? fNext = front?.next;\n            if (fNext != null) {\n                fNext.prev = null;\n                front!.next = null;\n            }\n            front = fNext;   // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else {\n            val = rear?.val;  // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            ListNode? rPrev = rear?.prev;\n            if (rPrev != null) {\n                rPrev.next = null;\n                rear!.prev = null;\n            }\n            rear = rPrev;    // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n\n        queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int? PopFirst() {\n        return Pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int? PopLast() {\n        return Pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int? PeekFirst() {\n        if (IsEmpty())\n            throw new Exception();\n        return front?.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int? PeekLast() {\n        if (IsEmpty())\n            throw new Exception();\n        return rear?.val;\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int?[] ToArray() {\n        ListNode? node = front;\n        int?[] res = new int?[Size()];\n        for (int i = 0; i < res.Length; i++) {\n            res[i] = node?.val;\n            node = node?.next;\n        }\n\n        return 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\n    data *list.List\n}\n\n/* \u521d\u59cb\u5316\u53cc\u7aef\u961f\u5217 */\nfunc newLinkedListDeque() *linkedListDeque {\n    return &linkedListDeque{\n        data: list.New(),\n    }\n}\n\n/* \u961f\u9996\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushFirst(value any) {\n    s.data.PushFront(value)\n}\n\n/* \u961f\u5c3e\u5143\u7d20\u5165\u961f */\nfunc (s *linkedListDeque) pushLast(value any) {\n    s.data.PushBack(value)\n}\n\n/* \u961f\u9996\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popFirst() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u961f\u5c3e\u5143\u7d20\u51fa\u961f */\nfunc (s *linkedListDeque) popLast() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListDeque) peekFirst() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (s *linkedListDeque) peekLast() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    return e.Value\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListDeque) size() int {\n    return s.data.Len()\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListDeque) isEmpty() bool {\n    return s.data.Len() == 0\n}\n\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListDeque) toList() *list.List {\n    return s.data\n}\n
    linkedlist_deque.swift
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    var val: Int // \u8282\u70b9\u503c\n    var next: ListNode? // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n    weak var prev: ListNode? // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\n    init(val: Int) {\n        self.val = val\n    }\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    private var front: ListNode? // \u5934\u8282\u70b9 front\n    private var rear: ListNode? // \u5c3e\u8282\u70b9 rear\n    private var queSize: Int // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    init() {\n        queSize = 0\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        queSize\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    private func push(num: Int, isFront: Bool) {\n        let node = ListNode(val: num)\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if isEmpty() {\n            front = node\n            rear = node\n        }\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        else if isFront {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            front?.prev = node\n            node.next = front\n            front = node // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n        else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            rear?.next = node\n            node.prev = rear\n            rear = node // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize += 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    func pushFirst(num: Int) {\n        push(num: num, isFront: true)\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    func pushLast(num: Int) {\n        push(num: num, isFront: false)\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    private func pop(isFront: Bool) -> Int {\n        if isEmpty() {\n            fatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        }\n        let val: Int\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if isFront {\n            val = front!.val // \u6682\u5b58\u5934\u8282\u70b9\u503c\n            // \u5220\u9664\u5934\u8282\u70b9\n            let fNext = front?.next\n            if fNext != nil {\n                fNext?.prev = nil\n                front?.next = nil\n            }\n            front = fNext // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else {\n            val = rear!.val // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n            // \u5220\u9664\u5c3e\u8282\u70b9\n            let rPrev = rear?.prev\n            if rPrev != nil {\n                rPrev?.next = nil\n                rear?.prev = nil\n            }\n            rear = rPrev // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        queSize -= 1 // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        return val\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    func popFirst() -> Int {\n        pop(isFront: true)\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    func popLast() -> Int {\n        pop(isFront: false)\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peekFirst() -> Int? {\n        isEmpty() ? nil : front?.val\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    func peekLast() -> Int? {\n        isEmpty() ? nil : rear?.val\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    func toArray() -> [Int] {\n        var node = front\n        var res = Array(repeating: 0, count: size())\n        for i in res.indices {\n            res[i] = node!.val\n            node = node?.next\n        }\n        return res\n    }\n}\n
    linkedlist_deque.js
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    val; // \u8282\u70b9\u503c\n\n    constructor(val) {\n        this.val = val;\n        this.next = null;\n        this.prev = null;\n    }\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\n\n    constructor() {\n        this.#front = null;\n        this.#rear = null;\n        this.#queSize = 0;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\n    pushLast(val) {\n        const node = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.#queSize === 0) {\n            this.#front = node;\n            this.#rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            this.#rear.next = node;\n            node.prev = this.#rear;\n            this.#rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        this.#queSize++;\n    }\n\n    /* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\n    pushFirst(val) {\n        const node = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.#queSize === 0) {\n            this.#front = node;\n            this.#rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            this.#front.prev = node;\n            node.next = this.#front;\n            this.#front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        this.#queSize++;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\n    popLast() {\n        if (this.#queSize === 0) {\n            return null;\n        }\n        const value = this.#rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5c3e\u8282\u70b9\n        let temp = this.#rear.prev;\n        if (temp !== null) {\n            temp.next = null;\n            this.#rear.prev = null;\n        }\n        this.#rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        this.#queSize--;\n        return value;\n    }\n\n    /* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\n    popFirst() {\n        if (this.#queSize === 0) {\n            return null;\n        }\n        const value = this.#front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5934\u8282\u70b9\n        let temp = this.#front.next;\n        if (temp !== null) {\n            temp.prev = null;\n            this.#front.next = null;\n        }\n        this.#front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\n        this.#queSize--;\n        return value;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast() {\n        return this.#queSize === 0 ? null : this.#rear.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst() {\n        return this.#queSize === 0 ? null : this.#front.val;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#queSize === 0;\n    }\n\n    /* \u6253\u5370\u53cc\u5411\u961f\u5217 */\n    print() {\n        const arr = [];\n        let temp = this.#front;\n        while (temp !== null) {\n            arr.push(temp.val);\n            temp = temp.next;\n        }\n        console.log('[' + arr.join(', ') + ']');\n    }\n}\n
    linkedlist_deque.ts
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n    prev: ListNode; // \u524d\u9a71\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    next: ListNode; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528 (\u6307\u9488)\n    val: number; // \u8282\u70b9\u503c\n\n    constructor(val: number) {\n        this.val = val;\n        this.next = null;\n        this.prev = null;\n    }\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass LinkedListDeque {\n    private front: ListNode; // \u5934\u8282\u70b9 front\n    private rear: ListNode; // \u5c3e\u8282\u70b9 rear\n    private queSize: number; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n    constructor() {\n        this.front = null;\n        this.rear = null;\n        this.queSize = 0;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f\u64cd\u4f5c */\n    pushLast(val: number): void {\n        const node: ListNode = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.queSize === 0) {\n            this.front = node;\n            this.rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n            this.rear.next = node;\n            node.prev = this.rear;\n            this.rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        }\n        this.queSize++;\n    }\n\n    /* \u961f\u9996\u5165\u961f\u64cd\u4f5c */\n    pushFirst(val: number): void {\n        const node: ListNode = new ListNode(val);\n        // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n        if (this.queSize === 0) {\n            this.front = node;\n            this.rear = node;\n        } else {\n            // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n            this.front.prev = node;\n            node.next = this.front;\n            this.front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n        }\n        this.queSize++;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c */\n    popLast(): number {\n        if (this.queSize === 0) {\n            return null;\n        }\n        const value: number = this.rear.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5c3e\u8282\u70b9\n        let temp: ListNode = this.rear.prev;\n        if (temp !== null) {\n            temp.next = null;\n            this.rear.prev = null;\n        }\n        this.rear = temp; // \u66f4\u65b0\u5c3e\u8282\u70b9\n        this.queSize--;\n        return value;\n    }\n\n    /* \u961f\u9996\u51fa\u961f\u64cd\u4f5c */\n    popFirst(): number {\n        if (this.queSize === 0) {\n            return null;\n        }\n        const value: number = this.front.val; // \u5b58\u50a8\u5c3e\u8282\u70b9\u503c\n        // \u5220\u9664\u5934\u8282\u70b9\n        let temp: ListNode = this.front.next;\n        if (temp !== null) {\n            temp.prev = null;\n            this.front.next = null;\n        }\n        this.front = temp; // \u66f4\u65b0\u5934\u8282\u70b9\n        this.queSize--;\n        return value;\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast(): number {\n        return this.queSize === 0 ? null : this.rear.val;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst(): number {\n        return this.queSize === 0 ? null : this.front.val;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.queSize === 0;\n    }\n\n    /* \u6253\u5370\u53cc\u5411\u961f\u5217 */\n    print(): void {\n        const arr: number[] = [];\n        let temp: ListNode = this.front;\n        while (temp !== null) {\n            arr.push(temp.val);\n            temp = temp.next;\n        }\n        console.log('[' + arr.join(', ') + ']');\n    }\n}\n
    linkedlist_deque.dart
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\nclass ListNode {\n  int val; // \u8282\u70b9\u503c\n  ListNode? next; // \u540e\u7ee7\u8282\u70b9\u5f15\u7528\n  ListNode? prev; // \u524d\u9a71\u8282\u70b9\u5f15\u7528\n\n  ListNode(this.val, {this.next, this.prev});\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u5bf9\u5217 */\nclass LinkedListDeque {\n  late ListNode? _front; // \u5934\u8282\u70b9 _front\n  late ListNode? _rear; // \u5c3e\u8282\u70b9 _rear\n  int _queSize = 0; // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n\n  LinkedListDeque() {\n    this._front = null;\n    this._rear = null;\n  }\n\n  /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u957f\u5ea6 */\n  int size() {\n    return this._queSize;\n  }\n\n  /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return size() == 0;\n  }\n\n  /* \u5165\u961f\u64cd\u4f5c */\n  void push(int _num, bool isFront) {\n    final ListNode node = ListNode(_num);\n    if (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;\n      node.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;\n      node.prev = _rear;\n      _rear = node; // \u66f4\u65b0\u5c3e\u8282\u70b9\n    }\n    _queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n  }\n\n  /* \u961f\u9996\u5165\u961f */\n  void pushFirst(int _num) {\n    push(_num, true);\n  }\n\n  /* \u961f\u5c3e\u5165\u961f */\n  void pushLast(int _num) {\n    push(_num, false);\n  }\n\n  /* \u51fa\u961f\u64cd\u4f5c */\n  int? pop(bool isFront) {\n    // \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de null\n    if (isEmpty()) {\n      return null;\n    }\n    final int val;\n    if (isFront) {\n      // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n      val = _front!.val; // \u6682\u5b58\u5934\u8282\u70b9\u503c\n      // \u5220\u9664\u5934\u8282\u70b9\n      ListNode? fNext = _front!.next;\n      if (fNext != null) {\n        fNext.prev = null;\n        _front!.next = null;\n      }\n      _front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n    } else {\n      // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n      val = _rear!.val; // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n      // \u5220\u9664\u5c3e\u8282\u70b9\n      ListNode? rPrev = _rear!.prev;\n      if (rPrev != null) {\n        rPrev.next = null;\n        _rear!.prev = null;\n      }\n      _rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n    }\n    _queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    return val;\n  }\n\n  /* \u961f\u9996\u51fa\u961f */\n  int? popFirst() {\n    return pop(true);\n  }\n\n  /* \u961f\u5c3e\u51fa\u961f */\n  int? popLast() {\n    return pop(false);\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int? peekFirst() {\n    return _front?.val;\n  }\n\n  /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n  int? peekLast() {\n    return _rear?.val;\n  }\n\n  /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n  List<int> toArray() {\n    ListNode? node = _front;\n    final List<int> res = [];\n    for (int i = 0; i < _queSize; i++) {\n      res.add(node!.val);\n      node = node.next;\n    }\n    return res;\n  }\n}\n
    linkedlist_deque.rs
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\npub struct ListNode<T> {\n    pub val: T,                                 // \u8282\u70b9\u503c\n    pub next: Option<Rc<RefCell<ListNode<T>>>>, // \u540e\u7ee7\u8282\u70b9\u6307\u9488\n    pub prev: Option<Rc<RefCell<ListNode<T>>>>, // \u524d\u9a71\u8282\u70b9\u6307\u9488\n}\n\nimpl<T> ListNode<T> {\n    pub fn new(val: T) -> Rc<RefCell<ListNode<T>>> {\n        Rc::new(RefCell::new(ListNode {\n            val,\n            next: None,\n            prev: None,\n        }))\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> {\n    front: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\n    rear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \n    que_size: usize,                            // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n}\n\nimpl<T: Copy> LinkedListDeque<T> {\n    pub fn new() -> Self {\n        Self {\n            front: None,\n            rear: None,\n            que_size: 0, \n        }\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        return self.que_size;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        return self.size() == 0;\n    }\n\n    /* \u5165\u961f\u64cd\u4f5c */\n    pub fn push(&mut self, num: T, is_front: bool) {\n        let node = ListNode::new(num);\n        // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n        if is_front {\n            match self.front.take() {\n                // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n                None => {\n                    self.rear = Some(node.clone());\n                    self.front = Some(node);\n                }\n                // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n                Some(old_front) => {\n                    old_front.borrow_mut().prev = Some(node.clone());\n                    node.borrow_mut().next = Some(old_front);\n                    self.front = Some(node); // \u66f4\u65b0\u5934\u8282\u70b9\n                }\n            }\n        } \n        // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n        else {\n            match self.rear.take() {\n                // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n                None => {\n                    self.front = Some(node.clone());\n                    self.rear = Some(node);\n                }\n                // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n                Some(old_rear) => {\n                    old_rear.borrow_mut().next = Some(node.clone());\n                    node.borrow_mut().prev = Some(old_rear);\n                    self.rear = Some(node); // \u66f4\u65b0\u5c3e\u8282\u70b9\n                }\n            }\n        }\n        self.que_size += 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pub fn push_first(&mut self, num: T) {\n        self.push(num, true);\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pub fn push_last(&mut self, num: T) {\n        self.push(num, false);\n    }\n\n    /* \u51fa\u961f\u64cd\u4f5c */\n    pub fn pop(&mut self, is_front: bool) -> Option<T> {\n        // \u82e5\u961f\u5217\u4e3a\u7a7a\uff0c\u76f4\u63a5\u8fd4\u56de None\n        if self.is_empty() { \n            return None \n        };\n        // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n        if is_front {\n            self.front.take().map(|old_front| {\n                match old_front.borrow_mut().next.take() {\n                    Some(new_front) => {\n                        new_front.borrow_mut().prev.take();\n                        self.front = Some(new_front);   // \u66f4\u65b0\u5934\u8282\u70b9\n                    }\n                    None => {\n                        self.rear.take();\n                    }\n                }\n                self.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n                Rc::try_unwrap(old_front).ok().unwrap().into_inner().val\n            })\n\n        } \n        // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n        else {\n            self.rear.take().map(|old_rear| {\n                match old_rear.borrow_mut().prev.take() {\n                    Some(new_rear) => {\n                        new_rear.borrow_mut().next.take();\n                        self.rear = Some(new_rear);     // \u66f4\u65b0\u5c3e\u8282\u70b9\n                    }\n                    None => {\n                        self.front.take();\n                    }\n                }\n                self.que_size -= 1; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n                Rc::try_unwrap(old_rear).ok().unwrap().into_inner().val\n            })\n        }\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    pub fn pop_first(&mut self) -> Option<T> {\n        return self.pop(true);\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    pub fn pop_last(&mut self) -> Option<T> {\n        return self.pop(false);\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    pub fn peek_first(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.front.as_ref()\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    pub fn peek_last(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.rear.as_ref()\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\n        if let Some(node) = head {\n            let mut nums = self.to_array(node.borrow().next.as_ref());\n            nums.insert(0, node.borrow().val);\n            return nums;\n        }\n        return Vec::new();\n    }\n}\n
    linkedlist_deque.c
    /* \u53cc\u5411\u94fe\u8868\u8282\u70b9 */\ntypedef struct DoublyListNode {\n    int val;                     // \u8282\u70b9\u503c\n    struct DoublyListNode *next; // \u540e\u7ee7\u8282\u70b9\n    struct DoublyListNode *prev; // \u524d\u9a71\u8282\u70b9\n} DoublyListNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nDoublyListNode *newDoublyListNode(int num) {\n    DoublyListNode *new = (DoublyListNode *)malloc(sizeof(DoublyListNode));\n    new->val = num;\n    new->next = NULL;\n    new->prev = NULL;\n    return new;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delDoublyListNode(DoublyListNode *node) {\n    free(node);\n}\n\n/* \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\n    DoublyListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    int queSize;                  // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n} LinkedListDeque;\n\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListDeque *newLinkedListDeque() {\n    LinkedListDeque *deque = (LinkedListDeque *)malloc(sizeof(LinkedListDeque));\n    deque->front = NULL;\n    deque->rear = NULL;\n    deque->queSize = 0;\n    return deque;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListdeque(LinkedListDeque *deque) {\n    // \u91ca\u653e\u6240\u6709\u8282\u70b9\n    for (int i = 0; i < deque->queSize && deque->front != NULL; i++) {\n        DoublyListNode *tmp = deque->front;\n        deque->front = deque->front->next;\n        free(tmp);\n    }\n    // \u91ca\u653e deque \u7ed3\u6784\u4f53\n    free(deque);\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListDeque *deque) {\n    return deque->queSize;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListDeque *deque) {\n    return (size(deque) == 0);\n}\n\n/* \u5165\u961f */\nvoid push(LinkedListDeque *deque, int num, bool isFront) {\n    DoublyListNode *node = newDoublyListNode(num);\n    // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411node\n    if (empty(deque)) {\n        deque->front = deque->rear = node;\n    }\n    // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n    else if (isFront) {\n        // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n        deque->front->prev = node;\n        node->next = deque->front;\n        deque->front = node; // \u66f4\u65b0\u5934\u8282\u70b9\n    }\n    // \u961f\u5c3e\u5165\u961f\u64cd\u4f5c\n    else {\n        // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5c3e\u90e8\n        deque->rear->next = node;\n        node->prev = deque->rear;\n        deque->rear = node;\n    }\n    deque->queSize++; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n}\n\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(LinkedListDeque *deque, int num) {\n    push(deque, num, true);\n}\n\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(LinkedListDeque *deque, int num) {\n    push(deque, num, false);\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(LinkedListDeque *deque) {\n    assert(size(deque) && deque->front);\n    return deque->front->val;\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(LinkedListDeque *deque) {\n    assert(size(deque) && deque->rear);\n    return deque->rear->val;\n}\n\n/* \u51fa\u961f */\nint pop(LinkedListDeque *deque, bool isFront) {\n    if (empty(deque))\n        return -1;\n    int val;\n    // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n    if (isFront) {\n        val = peekFirst(deque); // \u6682\u5b58\u5934\u8282\u70b9\u503c\n        DoublyListNode *fNext = deque->front->next;\n        if (fNext) {\n            fNext->prev = NULL;\n            deque->front->next = NULL;\n            delDoublyListNode(deque->front);\n        }\n        deque->front = fNext; // \u66f4\u65b0\u5934\u8282\u70b9\n    }\n    // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n    else {\n        val = peekLast(deque); // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n        DoublyListNode *rPrev = deque->rear->prev;\n        if (rPrev) {\n            rPrev->next = NULL;\n            deque->rear->prev = NULL;\n            delDoublyListNode(deque->rear);\n        }\n        deque->rear = rPrev; // \u66f4\u65b0\u5c3e\u8282\u70b9\n    }\n    deque->queSize--; // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n    return val;\n}\n\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(LinkedListDeque *deque) {\n    return pop(deque, true);\n}\n\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(LinkedListDeque *deque) {\n    return pop(deque, false);\n}\n\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListDeque(LinkedListDeque *deque) {\n    int *arr = malloc(sizeof(int) * deque->queSize);\n    // \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\n    int i;\n    DoublyListNode *node;\n    for (i = 0, node = deque->front; i < deque->queSize; i++) {\n        arr[i] = node->val;\n        node = node->next;\n    }\n    printArray(arr, deque->queSize);\n    free(arr);\n}\n
    linkedlist_deque.zig
    // \u53cc\u5411\u94fe\u8868\u8282\u70b9\nfn ListNode(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        val: T = undefined,     // \u8282\u70b9\u503c\n        next: ?*Self = null,    // \u540e\u7ee7\u8282\u70b9\u6307\u9488\n        prev: ?*Self = null,    // \u524d\u9a71\u8282\u70b9\u6307\u9488\n\n        // Initialize a list node with specific value\n        pub fn init(self: *Self, x: i32) void {\n            self.val = x;\n            self.next = null;\n            self.prev = null;\n        }\n    };\n}\n\n// \u57fa\u4e8e\u53cc\u5411\u94fe\u8868\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217\nfn LinkedListDeque(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        front: ?*ListNode(T) = null,                    // \u5934\u8282\u70b9 front\n        rear: ?*ListNode(T) = null,                     // \u5c3e\u8282\u70b9 rear\n        que_size: usize = 0,                             // \u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.front = null;\n            self.rear = null;\n            self.que_size = 0;\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.que_size;\n        }\n\n        // \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u5165\u961f\u64cd\u4f5c\n        pub fn push(self: *Self, num: T, is_front: bool) !void {\n            var node = try self.mem_allocator.create(ListNode(T));\n            node.init(num);\n            // \u82e5\u94fe\u8868\u4e3a\u7a7a\uff0c\u5219\u4ee4 front \u548c rear \u90fd\u6307\u5411 node\n            if (self.isEmpty()) {\n                self.front = node;\n                self.rear = node;\n            // \u961f\u9996\u5165\u961f\u64cd\u4f5c\n            } else if (is_front) {\n                // \u5c06 node \u6dfb\u52a0\u81f3\u94fe\u8868\u5934\u90e8\n                self.front.?.prev = node;\n                node.next = self.front;\n                self.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\n                self.rear.?.next = node;\n                node.prev = self.rear;\n                self.rear = node;   // \u66f4\u65b0\u5c3e\u8282\u70b9\n            }\n            self.que_size += 1;      // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n        } \n\n        // \u961f\u9996\u5165\u961f\n        pub fn pushFirst(self: *Self, num: T) !void {\n            try self.push(num, true);\n        } \n\n        // \u961f\u5c3e\u5165\u961f\n        pub fn pushLast(self: *Self, num: T) !void {\n            try self.push(num, false);\n        } \n\n        // \u51fa\u961f\u64cd\u4f5c\n        pub fn pop(self: *Self, is_front: bool) T {\n            if (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n            var val: T = undefined;\n            // \u961f\u9996\u51fa\u961f\u64cd\u4f5c\n            if (is_front) {\n                val = self.front.?.val;     // \u6682\u5b58\u5934\u8282\u70b9\u503c\n                // \u5220\u9664\u5934\u8282\u70b9\n                var fNext = self.front.?.next;\n                if (fNext != null) {\n                    fNext.?.prev = null;\n                    self.front.?.next = null;\n                }\n                self.front = fNext;         // \u66f4\u65b0\u5934\u8282\u70b9\n            // \u961f\u5c3e\u51fa\u961f\u64cd\u4f5c\n            } else {\n                val = self.rear.?.val;      // \u6682\u5b58\u5c3e\u8282\u70b9\u503c\n                // \u5220\u9664\u5c3e\u8282\u70b9\n                var rPrev = self.rear.?.prev;\n                if (rPrev != null) {\n                    rPrev.?.next = null;\n                    self.rear.?.prev = null;\n                }\n                self.rear = rPrev;          // \u66f4\u65b0\u5c3e\u8282\u70b9\n            }\n            self.que_size -= 1;              // \u66f4\u65b0\u961f\u5217\u957f\u5ea6\n            return val;\n        } \n\n        // \u961f\u9996\u51fa\u961f\n        pub fn popFirst(self: *Self) T {\n            return self.pop(true);\n        } \n\n        // \u961f\u5c3e\u51fa\u961f\n        pub fn popLast(self: *Self) T {\n            return self.pop(false);\n        } \n\n        // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\n        pub fn peekFirst(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n            return self.front.?.val;\n        }  \n\n        // \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\n        pub fn peekLast(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n            return self.rear.?.val;\n        }\n\n        // \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370\n        pub fn toArray(self: *Self) ![]T {\n            var node = self.front;\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            while (i < res.len) : (i += 1) {\n                res[i] = node.?.val;\n                node = node.?.next;\n            }\n            return 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\"\"\"\n\n    def __init__(self, capacity: int):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._nums: list[int] = [0] * capacity\n        self._front: int = 0\n        self._size: int = 0\n\n    def capacity(self) -> int:\n        \"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\n        return len(self._nums)\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self._size == 0\n\n    def 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\n        return (i + self.capacity()) % self.capacity()\n\n    def push_first(self, num: int):\n        \"\"\"\u961f\u9996\u5165\u961f\"\"\"\n        if self._size == self.capacity():\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        # \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        # \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        self._front = self.index(self._front - 1)\n        # \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        self._nums[self._front] = num\n        self._size += 1\n\n    def push_last(self, num: int):\n        \"\"\"\u961f\u5c3e\u5165\u961f\"\"\"\n        if self._size == self.capacity():\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        # \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        rear = self.index(self._front + self._size)\n        # \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self._nums[rear] = num\n        self._size += 1\n\n    def pop_first(self) -> int:\n        \"\"\"\u961f\u9996\u51fa\u961f\"\"\"\n        num = self.peek_first()\n        # \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        self._front = self.index(self._front + 1)\n        self._size -= 1\n        return num\n\n    def pop_last(self) -> int:\n        \"\"\"\u961f\u5c3e\u51fa\u961f\"\"\"\n        num = self.peek_last()\n        self._size -= 1\n        return num\n\n    def peek_first(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        return self._nums[self._front]\n\n    def peek_last(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u5c3e\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        # \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        last = self.index(self._front + self._size - 1)\n        return self._nums[last]\n\n    def 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\n        res = []\n        for i in range(self._size):\n            res.append(self._nums[self.index(self._front + i)])\n        return res\n
    array_deque.cpp
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n  private:\n    vector<int> nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;        // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;      // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    ArrayDeque(int capacity) {\n        nums.resize(capacity);\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    int capacity() {\n        return nums.size();\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    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\n        return (i + capacity()) % capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    void pushFirst(int num) {\n        if (queSize == capacity()) {\n            cout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\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\n    /* \u961f\u5c3e\u5165\u961f */\n    void pushLast(int num) {\n        if (queSize == capacity()) {\n            cout << \"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\" << endl;\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        int rear = index(front + queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    int popFirst() {\n        int num = peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = index(front + 1);\n        queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    int popLast() {\n        int num = peekLast();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peekFirst() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        return nums[front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    int peekLast() {\n        if (isEmpty())\n            throw out_of_range(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        int last = index(front + queSize - 1);\n        return nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    vector<int> toVector() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        vector<int> res(queSize);\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[index(j)];\n        }\n        return res;\n    }\n};\n
    array_deque.java
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    private int[] nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private int queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public ArrayDeque(int capacity) {\n        this.nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    public int capacity() {\n        return nums.length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    private 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\n        return (i + capacity()) % capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void pushFirst(int num) {\n        if (queSize == capacity()) {\n            System.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\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\n    /* \u961f\u5c3e\u5165\u961f */\n    public void pushLast(int num) {\n        if (queSize == capacity()) {\n            System.out.println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        int rear = index(front + queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int popFirst() {\n        int num = peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = index(front + 1);\n        queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int popLast() {\n        int num = peekLast();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peekFirst() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return nums[front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int peekLast() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        int last = index(front + queSize - 1);\n        return nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int[] toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.cs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    int[] nums;  // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public ArrayDeque(int capacity) {\n        nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    int Capacity() {\n        return nums.Length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    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\n        return (i + Capacity()) % Capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    public void PushFirst(int num) {\n        if (queSize == Capacity()) {\n            Console.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\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\n    /* \u961f\u5c3e\u5165\u961f */\n    public void PushLast(int num) {\n        if (queSize == Capacity()) {\n            Console.WriteLine(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        int rear = Index(front + queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    public int PopFirst() {\n        int num = PeekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = Index(front + 1);\n        queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    public int PopLast() {\n        int num = PeekLast();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int PeekFirst() {\n        if (IsEmpty()) {\n            throw new InvalidOperationException();\n        }\n        return nums[front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    public int PeekLast() {\n        if (IsEmpty()) {\n            throw new InvalidOperationException();\n        }\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        int last = Index(front + queSize - 1);\n        return nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    public int[] ToArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[Index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.go
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntype arrayDeque struct {\n    nums        []int // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    queSize     int   // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n    queCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayDeque(queCapacity int) *arrayDeque {\n    return &arrayDeque{\n        nums:        make([]int, queCapacity),\n        queCapacity: queCapacity,\n        front:       0,\n        queSize:     0,\n    }\n}\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayDeque) size() int {\n    return q.queSize\n}\n\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayDeque) isEmpty() bool {\n    return q.queSize == 0\n}\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\n    return (i + q.queCapacity) % q.queCapacity\n}\n\n/* \u961f\u9996\u5165\u961f */\nfunc (q *arrayDeque) pushFirst(num int) {\n    if q.queSize == q.queCapacity {\n        fmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n        return\n    }\n    // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n    q.front = q.index(q.front - 1)\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n    q.nums[q.front] = num\n    q.queSize++\n}\n\n/* \u961f\u5c3e\u5165\u961f */\nfunc (q *arrayDeque) pushLast(num int) {\n    if q.queSize == q.queCapacity {\n        fmt.Println(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n        return\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    rear := q.index(q.front + q.queSize)\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n    q.nums[rear] = num\n    q.queSize++\n}\n\n/* \u961f\u9996\u51fa\u961f */\nfunc (q *arrayDeque) popFirst() any {\n    num := q.peekFirst()\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    q.front = q.index(q.front + 1)\n    q.queSize--\n    return num\n}\n\n/* \u961f\u5c3e\u51fa\u961f */\nfunc (q *arrayDeque) popLast() any {\n    num := q.peekLast()\n    q.queSize--\n    return num\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayDeque) peekFirst() any {\n    if q.isEmpty() {\n        return nil\n    }\n    return q.nums[q.front]\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nfunc (q *arrayDeque) peekLast() any {\n    if q.isEmpty() {\n        return nil\n    }\n    // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n    last := q.index(q.front + q.queSize - 1)\n    return q.nums[last]\n}\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\n    res := make([]int, q.queSize)\n    for i, j := 0, q.front; i < q.queSize; i++ {\n        res[i] = q.nums[q.index(j)]\n        j++\n    }\n    return res\n}\n
    array_deque.swift
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    private var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private var front: Int // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private var queSize: Int // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init(capacity: Int) {\n        nums = Array(repeating: 0, count: capacity)\n        front = 0\n        queSize = 0\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    func capacity() -> Int {\n        nums.count\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        queSize\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    private 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\n    /* \u961f\u9996\u5165\u961f */\n    func pushFirst(num: Int) {\n        if size() == capacity() {\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        front = index(i: front - 1)\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        nums[front] = num\n        queSize += 1\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    func pushLast(num: Int) {\n        if size() == capacity() {\n            print(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\")\n            return\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        let rear = index(i: front + size())\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num\n        queSize += 1\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    func popFirst() -> Int {\n        let num = peekFirst()\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        front = index(i: front + 1)\n        queSize -= 1\n        return num\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    func popLast() -> Int {\n        let num = peekLast()\n        queSize -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peekFirst() -> Int {\n        if isEmpty() {\n            fatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        }\n        return nums[front]\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    func peekLast() -> Int {\n        if isEmpty() {\n            fatalError(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\")\n        }\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        let last = index(i: front + size() - 1)\n        return nums[last]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    func toArray() -> [Int] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        var res = Array(repeating: 0, count: size())\n        for (i, j) in sequence(first: (0, front), next: { $0 < self.size() - 1 ? ($0 + 1, $1 + 1) : nil }) {\n            res[i] = nums[index(i: j)]\n        }\n        return 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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(capacity) {\n        this.#nums = new Array(capacity);\n        this.#front = 0;\n        this.#queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    capacity() {\n        return this.#nums.length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#queSize === 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    index(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\n        return (i + this.capacity()) % this.capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pushFirst(num) {\n        if (this.#queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        this.#front = this.index(this.#front - 1);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        this.#nums[this.#front] = num;\n        this.#queSize++;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pushLast(num) {\n        if (this.#queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        const rear = this.index(this.#front + this.#queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.#nums[rear] = num;\n        this.#queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    popFirst() {\n        const num = this.peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        this.#front = this.index(this.#front + 1);\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    popLast() {\n        const num = this.peekLast();\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst() {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        return this.#nums[this.#front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast() {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        const last = this.index(this.#front + this.#queSize - 1);\n        return this.#nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const res = [];\n        for (let i = 0, j = this.#front; i < this.#queSize; i++, j++) {\n            res[i] = this.#nums[this.index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.ts
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n    private nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private queSize: number; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(capacity: number) {\n        this.nums = new Array(capacity);\n        this.front = 0;\n        this.queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    capacity(): number {\n        return this.nums.length;\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.queSize === 0;\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    index(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\n        return (i + this.capacity()) % this.capacity();\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pushFirst(num: number): void {\n        if (this.queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        this.front = this.index(this.front - 1);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        this.nums[this.front] = num;\n        this.queSize++;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pushLast(num: number): void {\n        if (this.queSize === this.capacity()) {\n            console.log('\u53cc\u5411\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        const rear: number = this.index(this.front + this.queSize);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.nums[rear] = num;\n        this.queSize++;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    popFirst(): number {\n        const num: number = this.peekFirst();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        this.front = this.index(this.front + 1);\n        this.queSize--;\n        return num;\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    popLast(): number {\n        const num: number = this.peekLast();\n        this.queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peekFirst(): number {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        return this.nums[this.front];\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    peekLast(): number {\n        if (this.isEmpty()) throw new Error('The Deque Is Empty.');\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        const last = this.index(this.front + this.queSize - 1);\n        return this.nums[last];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    toArray(): number[] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const res: number[] = [];\n        for (let i = 0, j = this.front; i < this.queSize; i++, j++) {\n            res[i] = this.nums[this.index(j)];\n        }\n        return res;\n    }\n}\n
    array_deque.dart
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nclass ArrayDeque {\n  late List<int> _nums; // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n  late int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n  late int _queSize; // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  ArrayDeque(int capacity) {\n    this._nums = List.filled(capacity, 0);\n    this._front = this._queSize = 0;\n  }\n\n  /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n  int capacity() {\n    return _nums.length;\n  }\n\n  /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n  int size() {\n    return _queSize;\n  }\n\n  /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _queSize == 0;\n  }\n\n  /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n  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\n    return (i + capacity()) % capacity();\n  }\n\n  /* \u961f\u9996\u5165\u961f */\n  void pushFirst(int _num) {\n    if (_queSize == capacity()) {\n      throw 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\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\n  /* \u961f\u5c3e\u5165\u961f */\n  void pushLast(int _num) {\n    if (_queSize == capacity()) {\n      throw Exception(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    int rear = index(_front + _queSize);\n    // \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    _nums[rear] = _num;\n    _queSize++;\n  }\n\n  /* \u961f\u9996\u51fa\u961f */\n  int popFirst() {\n    int _num = peekFirst();\n    // \u961f\u9996\u6307\u9488\u5411\u53f3\u79fb\u52a8\u4e00\u4f4d\n    _front = index(_front + 1);\n    _queSize--;\n    return _num;\n  }\n\n  /* \u961f\u5c3e\u51fa\u961f */\n  int popLast() {\n    int _num = peekLast();\n    _queSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int peekFirst() {\n    if (isEmpty()) {\n      throw Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n    }\n    return _nums[_front];\n  }\n\n  /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n  int peekLast() {\n    if (isEmpty()) {\n      throw Exception(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\");\n    }\n    // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n    int last = index(_front + _queSize - 1);\n    return _nums[last];\n  }\n\n  /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n  List<int> toArray() {\n    // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n    List<int> res = List.filled(_queSize, 0);\n    for (int i = 0, j = _front; i < _queSize; i++, j++) {\n      res[i] = _nums[index(j)];\n    }\n    return res;\n  }\n}\n
    array_deque.rs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\nstruct ArrayDeque {\n    nums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u53cc\u5411\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front: usize,       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    que_size: usize,    // \u53cc\u5411\u961f\u5217\u957f\u5ea6\n}\n\nimpl ArrayDeque {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    pub fn new(capacity: usize) -> Self {\n        Self {\n            nums: vec![0; capacity],\n            front: 0,\n            que_size: 0,\n        }\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\n    pub fn capacity(&self) -> usize {\n        self.nums.len()\n    }\n\n    /* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        self.que_size\n    }\n\n    /* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        self.que_size == 0\n    }\n\n    /* \u8ba1\u7b97\u73af\u5f62\u6570\u7ec4\u7d22\u5f15 */\n    fn 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\n        return ((i + self.capacity() as i32) % self.capacity() as i32) as usize;\n    }\n\n    /* \u961f\u9996\u5165\u961f */\n    pub fn push_first(&mut self, num: i32) {\n        if self.que_size == self.capacity() {\n            println!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return\n        }\n        // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u540e\u56de\u5230\u5c3e\u90e8\n        self.front = self.index(self.front as i32 - 1);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u9996\n        self.nums[self.front] = num;\n        self.que_size += 1;\n    }\n\n    /* \u961f\u5c3e\u5165\u961f */\n    pub fn push_last(&mut self, num: i32) {\n        if self.que_size == self.capacity() {\n            println!(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\");\n            return\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        let rear = self.index(self.front as i32 + self.que_size as i32);\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self.nums[rear] = num;\n        self.que_size += 1;\n    }\n\n    /* \u961f\u9996\u51fa\u961f */\n    fn pop_first(&mut self) -> i32 {\n        let num = self.peek_first();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n        self.front = self.index(self.front as i32 + 1);\n        self.que_size -= 1;\n        num\n    }\n\n    /* \u961f\u5c3e\u51fa\u961f */\n    fn pop_last(&mut self) -> i32 {\n        let num = self.peek_last();\n        self.que_size -= 1;\n        num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    fn peek_first(&self) -> i32 {\n        if self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\n        self.nums[self.front]\n    }\n\n    /* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\n    fn peek_last(&self) -> i32 {\n        if self.is_empty() { panic!(\"\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\") };\n        // \u8ba1\u7b97\u5c3e\u5143\u7d20\u7d22\u5f15\n        let last = self.index(self.front as i32 + self.que_size as i32 - 1);\n        self.nums[last]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4\u7528\u4e8e\u6253\u5370 */\n    fn to_array(&self) -> Vec<i32> {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        let mut res = vec![0; self.que_size];\n        let mut j = self.front;\n        for i in 0..self.que_size {\n            res[i] = self.nums[self.index(j as i32)];\n            j += 1;\n        }\n        res\n    }\n}\n
    array_deque.c
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u53cc\u5411\u961f\u5217 */\ntypedef struct {\n    int *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\n    int queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayDeque;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayDeque *newArrayDeque(int capacity) {\n    ArrayDeque *deque = (ArrayDeque *)malloc(sizeof(ArrayDeque));\n    // \u521d\u59cb\u5316\u6570\u7ec4\n    deque->queCapacity = capacity;\n    deque->nums = (int *)malloc(sizeof(int) * deque->queCapacity);\n    deque->front = deque->queSize = 0;\n    return deque;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayDeque(ArrayDeque *deque) {\n    free(deque->nums);\n    free(deque);\n}\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayDeque *deque) {\n    return deque->queCapacity;\n}\n\n/* \u83b7\u53d6\u53cc\u5411\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayDeque *deque) {\n    return deque->queSize;\n}\n\n/* \u5224\u65ad\u53cc\u5411\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayDeque *deque) {\n    return deque->queSize == 0;\n}\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\n    return ((i + capacity(deque)) % capacity(deque));\n}\n\n/* \u961f\u9996\u5165\u961f */\nvoid pushFirst(ArrayDeque *deque, int num) {\n    if (deque->queSize == capacity(deque)) {\n        printf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\n        return;\n    }\n    // \u961f\u9996\u6307\u9488\u5411\u5de6\u79fb\u52a8\u4e00\u4f4d\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 front \u8d8a\u8fc7\u6570\u7ec4\u5934\u90e8\u56de\u5230\u5c3e\u90e8\n    deque->front = dequeIndex(deque, deque->front - 1);\n    // \u5c06 num \u6dfb\u52a0\u5230\u961f\u9996\n    deque->nums[deque->front] = num;\n    deque->queSize++;\n}\n\n/* \u961f\u5c3e\u5165\u961f */\nvoid pushLast(ArrayDeque *deque, int num) {\n    if (deque->queSize == capacity(deque)) {\n        printf(\"\u53cc\u5411\u961f\u5217\u5df2\u6ee1\\r\\n\");\n        return;\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    int rear = dequeIndex(deque, deque->front + deque->queSize);\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    deque->nums[rear] = num;\n    deque->queSize++;\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peekFirst(ArrayDeque *deque) {\n    // \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\n    assert(empty(deque) == 0);\n    return deque->nums[deque->front];\n}\n\n/* \u8bbf\u95ee\u961f\u5c3e\u5143\u7d20 */\nint peekLast(ArrayDeque *deque) {\n    // \u8bbf\u95ee\u5f02\u5e38\uff1a\u53cc\u5411\u961f\u5217\u4e3a\u7a7a\n    assert(empty(deque) == 0);\n    int last = dequeIndex(deque, deque->front + deque->queSize - 1);\n    return deque->nums[last];\n}\n\n/* \u961f\u9996\u51fa\u961f */\nint popFirst(ArrayDeque *deque) {\n    int num = peekFirst(deque);\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\n    deque->front = dequeIndex(deque, deque->front + 1);\n    deque->queSize--;\n    return num;\n}\n\n/* \u961f\u5c3e\u51fa\u961f */\nint popLast(ArrayDeque *deque) {\n    int num = peekLast(deque);\n    deque->queSize--;\n    return 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\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\n# \u5143\u7d20\u5165\u961f\nque.append(1)\nque.append(3)\nque.append(2)\nque.append(5)\nque.append(4)\n\n# \u8bbf\u95ee\u961f\u9996\u5143\u7d20\nfront: int = que[0];\n\n# \u5143\u7d20\u51fa\u961f\npop: int = que.popleft()\n\n# \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\nsize: int = len(que)\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint front = queue.front();\n\n/* \u5143\u7d20\u51fa\u961f */\nqueue.pop();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.offer(1);\nqueue.offer(3);\nqueue.offer(2);\nqueue.offer(5);\nqueue.offer(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.peek();\n\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.poll();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.size();\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.Enqueue(1);\nqueue.Enqueue(3);\nqueue.Enqueue(2);\nqueue.Enqueue(5);\nqueue.Enqueue(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.Peek();\n\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.Dequeue();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.Count;\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.PushBack(1)\nqueue.PushBack(3)\nqueue.PushBack(2)\nqueue.PushBack(5)\nqueue.PushBack(4)\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\npeek := queue.Front()\n\n/* \u5143\u7d20\u51fa\u961f */\npop := queue.Front()\nqueue.Remove(pop)\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nsize := queue.Len()\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.append(1)\nqueue.append(3)\nqueue.append(2)\nqueue.append(5)\nqueue.append(4)\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nlet peek = queue.first!\n\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\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = queue.count\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n\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\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.push(1);\nqueue.push(3);\nqueue.push(2);\nqueue.push(5);\nqueue.push(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nconst peek = queue[0];\n\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\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nconst size = queue.length;\n\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\n/* \u5143\u7d20\u5165\u961f */\nqueue.add(1);\nqueue.add(3);\nqueue.add(2);\nqueue.add(5);\nqueue.add(4);\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek = queue.first;\n\n/* \u5143\u7d20\u51fa\u961f */\nint pop = queue.removeFirst();\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size = queue.length;\n\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\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\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nif let Some(front) = deque.front() {\n}\n\n/* \u5143\u7d20\u51fa\u961f */\nif let Some(pop) = deque.pop_front() {\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nlet size = deque.len();\n\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\uff0c\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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._front: ListNode | None = None  # \u5934\u8282\u70b9 front\n        self._rear: ListNode | None = None  # \u5c3e\u8282\u70b9 rear\n        self._size: int = 0\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return not self._front\n\n    def push(self, num: int):\n        \"\"\"\u5165\u961f\"\"\"\n        # \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        node = ListNode(num)\n        # \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n        if self._front is None:\n            self._front = node\n            self._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:\n            self._rear.next = node\n            self._rear = node\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u961f\"\"\"\n        num = self.peek()\n        # \u5220\u9664\u5934\u8282\u70b9\n        self._front = self._front.next\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\n        return self._front.val\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        queue = []\n        temp = self._front\n        while temp:\n            queue.append(temp.val)\n            temp = temp.next\n        return queue\n
    linkedlist_queue.cpp
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n  private:\n    ListNode *front, *rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    int queSize;\n\n  public:\n    LinkedListQueue() {\n        front = nullptr;\n        rear = nullptr;\n        queSize = 0;\n    }\n\n    ~LinkedListQueue() {\n        // \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n        freeMemoryLinkedList(front);\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u5165\u961f */\n    void push(int num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        ListNode *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\n        if (front == nullptr) {\n            front = node;\n            rear = node;\n        }\n        // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n        else {\n            rear->next = node;\n            rear = node;\n        }\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    int pop() {\n        int num = peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        ListNode *tmp = front;\n        front = front->next;\n        // \u91ca\u653e\u5185\u5b58\n        delete tmp;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peek() {\n        if (size() == 0)\n            throw out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\n        return front->val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\n    vector<int> toVector() {\n        ListNode *node = front;\n        vector<int> res(size());\n        for (int i = 0; i < res.size(); i++) {\n            res[i] = node->val;\n            node = node->next;\n        }\n        return res;\n    }\n};\n
    linkedlist_queue.java
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    private ListNode front, rear; // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear\n    private int queSize = 0;\n\n    public LinkedListQueue() {\n        front = null;\n        rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f */\n    public void push(int num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        ListNode 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\n        if (front == null) {\n            front = node;\n            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 {\n            rear.next = node;\n            rear = node;\n        }\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int pop() {\n        int num = peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        front = front.next;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return front.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] toArray() {\n        ListNode node = front;\n        int[] res = new int[size()];\n        for (int i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_queue.cs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    ListNode? front, rear;  // \u5934\u8282\u70b9 front \uff0c\u5c3e\u8282\u70b9 rear \n    int queSize = 0;\n\n    public LinkedListQueue() {\n        front = null;\n        rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u961f */\n    public void Push(int num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        ListNode node = new(num);\n        // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n        if (front == null) {\n            front = node;\n            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 if (rear != null) {\n            rear.next = node;\n            rear = node;\n        }\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int Pop() {\n        int num = Peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        front = front?.next;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return front!.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] ToArray() {\n        if (front == null)\n            return [];\n\n        ListNode? node = front;\n        int[] res = new int[Size()];\n        for (int i = 0; i < res.Length; i++) {\n            res[i] = node!.val;\n            node = node.next;\n        }\n        return 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\n    data *list.List\n}\n\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newLinkedListQueue() *linkedListQueue {\n    return &linkedListQueue{\n        data: list.New(),\n    }\n}\n\n/* \u5165\u961f */\nfunc (s *linkedListQueue) push(value any) {\n    s.data.PushBack(value)\n}\n\n/* \u51fa\u961f */\nfunc (s *linkedListQueue) pop() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (s *linkedListQueue) peek() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Front()\n    return e.Value\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (s *linkedListQueue) size() int {\n    return s.data.Len()\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListQueue) isEmpty() bool {\n    return s.data.Len() == 0\n}\n\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListQueue) toList() *list.List {\n    return s.data\n}\n
    linkedlist_queue.swift
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    private var front: ListNode? // \u5934\u8282\u70b9\n    private var rear: ListNode? // \u5c3e\u8282\u70b9\n    private var _size = 0\n\n    init() {}\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        _size\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u5165\u961f */\n    func push(num: Int) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        let 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\n        if front == nil {\n            front = node\n            rear = node\n        }\n        // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n        else {\n            rear?.next = node\n            rear = node\n        }\n        _size += 1\n    }\n\n    /* \u51fa\u961f */\n    @discardableResult\n    func pop() -> Int {\n        let num = peek()\n        // \u5220\u9664\u5934\u8282\u70b9\n        front = front?.next\n        _size -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n        }\n        return front!.val\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    func toArray() -> [Int] {\n        var node = front\n        var res = Array(repeating: 0, count: size())\n        for i in res.indices {\n            res[i] = node!.val\n            node = node?.next\n        }\n        return 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;\n\n    constructor() {\n        this.#front = null;\n        this.#rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.size === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        const 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\n        if (!this.#front) {\n            this.#front = node;\n            this.#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 {\n            this.#rear.next = node;\n            this.#rear = node;\n        }\n        this.#queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop() {\n        const num = this.peek();\n        // \u5220\u9664\u5934\u8282\u70b9\n        this.#front = this.#front.next;\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek() {\n        if (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.#front.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray() {\n        let node = this.#front;\n        const res = new Array(this.size);\n        for (let i = 0; i < res.length; i++) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_queue.ts
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n    private front: ListNode | null; // \u5934\u8282\u70b9 front\n    private rear: ListNode | null; // \u5c3e\u8282\u70b9 rear\n    private queSize: number = 0;\n\n    constructor() {\n        this.front = null;\n        this.rear = null;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.size === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num: number): void {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        const 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\n        if (!this.front) {\n            this.front = node;\n            this.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 {\n            this.rear!.next = node;\n            this.rear = node;\n        }\n        this.queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop(): number {\n        const num = this.peek();\n        if (!this.front) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        // \u5220\u9664\u5934\u8282\u70b9\n        this.front = this.front.next;\n        this.queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek(): number {\n        if (this.size === 0) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.front!.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray(): number[] {\n        let node = this.front;\n        const res = new Array<number>(this.size);\n        for (let i = 0; i < res.length; i++) {\n            res[i] = node!.val;\n            node = node!.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_queue.dart
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\nclass LinkedListQueue {\n  ListNode? _front; // \u5934\u8282\u70b9 _front\n  ListNode? _rear; // \u5c3e\u8282\u70b9 _rear\n  int _queSize = 0; // \u961f\u5217\u957f\u5ea6\n\n  LinkedListQueue() {\n    _front = null;\n    _rear = null;\n  }\n\n  /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n  int size() {\n    return _queSize;\n  }\n\n  /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _queSize == 0;\n  }\n\n  /* \u5165\u961f */\n  void push(int _num) {\n    // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 _num\n    final node = ListNode(_num);\n    // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n    if (_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\n  /* \u51fa\u961f */\n  int pop() {\n    final int _num = peek();\n    // \u5220\u9664\u5934\u8282\u70b9\n    _front = _front!.next;\n    _queSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int peek() {\n    if (_queSize == 0) {\n      throw Exception('\u961f\u5217\u4e3a\u7a7a');\n    }\n    return _front!.val;\n  }\n\n  /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n  List<int> toArray() {\n    ListNode? node = _front;\n    final List<int> queue = [];\n    while (node != null) {\n      queue.add(node.val);\n      node = node.next;\n    }\n    return queue;\n  }\n}\n
    linkedlist_queue.rs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\n#[allow(dead_code)]\npub struct LinkedListQueue<T> {\n    front: Option<Rc<RefCell<ListNode<T>>>>,    // \u5934\u8282\u70b9 front\n    rear: Option<Rc<RefCell<ListNode<T>>>>,     // \u5c3e\u8282\u70b9 rear \n    que_size: usize,                            // \u961f\u5217\u7684\u957f\u5ea6\n}\n\nimpl<T: Copy> LinkedListQueue<T> {\n    pub fn new() -> Self {\n        Self {\n            front: None,\n            rear: None,\n            que_size: 0, \n        }\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        return self.que_size;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        return self.size() == 0;\n    }\n\n    /* \u5165\u961f */\n    pub fn push(&mut self, num: T) {\n        // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n        let new_rear = ListNode::new(num);\n        match self.rear.take() {\n            // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n            Some(old_rear) => {\n                old_rear.borrow_mut().next = Some(new_rear.clone());\n                self.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\n            None => {\n                self.front = Some(new_rear.clone());\n                self.rear = Some(new_rear);\n            }\n        }\n        self.que_size += 1;\n    }\n\n    /* \u51fa\u961f */\n    pub fn pop(&mut self) -> Option<T> {\n        self.front.take().map(|old_front| {\n            match old_front.borrow_mut().next.take() {\n                Some(new_front) => {\n                    self.front = Some(new_front);\n                }\n                None => {\n                    self.rear.take();\n                }\n            }\n            self.que_size -= 1;\n            Rc::try_unwrap(old_front).ok().unwrap().into_inner().val\n        })\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    pub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.front.as_ref()\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\n        if let Some(node) = head {\n            let mut nums = self.to_array(node.borrow().next.as_ref());\n            nums.insert(0, node.borrow().val);\n            return nums;\n        }\n        return Vec::new();\n    }\n}\n
    linkedlist_queue.c
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\n    ListNode *front, *rear;\n    int queSize;\n} LinkedListQueue;\n\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListQueue *newLinkedListQueue() {\n    LinkedListQueue *queue = (LinkedListQueue *)malloc(sizeof(LinkedListQueue));\n    queue->front = NULL;\n    queue->rear = NULL;\n    queue->queSize = 0;\n    return queue;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListQueue(LinkedListQueue *queue) {\n    // \u91ca\u653e\u6240\u6709\u8282\u70b9\n    for (int i = 0; i < queue->queSize && queue->front != NULL; i++) {\n        ListNode *tmp = queue->front;\n        queue->front = queue->front->next;\n        free(tmp);\n    }\n    // \u91ca\u653e queue \u7ed3\u6784\u4f53\n    free(queue);\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(LinkedListQueue *queue) {\n    return queue->queSize;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(LinkedListQueue *queue) {\n    return (size(queue) == 0);\n}\n\n/* \u5165\u961f */\nvoid push(LinkedListQueue *queue, int num) {\n    // \u5c3e\u8282\u70b9\u5904\u6dfb\u52a0 node\n    ListNode *node = newListNode(num);\n    // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n    if (queue->front == NULL) {\n        queue->front = node;\n        queue->rear = node;\n    }\n    // \u5982\u679c\u961f\u5217\u4e0d\u4e3a\u7a7a\uff0c\u5219\u5c06\u8be5\u8282\u70b9\u6dfb\u52a0\u5230\u5c3e\u8282\u70b9\u540e\n    else {\n        queue->rear->next = node;\n        queue->rear = node;\n    }\n    queue->queSize++;\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(LinkedListQueue *queue) {\n    assert(size(queue) && queue->front);\n    return queue->front->val;\n}\n\n/* \u51fa\u961f */\nint pop(LinkedListQueue *queue) {\n    int num = peek(queue);\n    ListNode *tmp = queue->front;\n    queue->front = queue->front->next;\n    free(tmp);\n    queue->queSize--;\n    return num;\n}\n\n/* \u6253\u5370\u961f\u5217 */\nvoid printLinkedListQueue(LinkedListQueue *queue) {\n    int *arr = malloc(sizeof(int) * queue->queSize);\n    // \u62f7\u8d1d\u94fe\u8868\u4e2d\u7684\u6570\u636e\u5230\u6570\u7ec4\n    int i;\n    ListNode *node;\n    for (i = 0, node = queue->front; i < queue->queSize; i++) {\n        arr[i] = node->val;\n        node = node->next;\n    }\n    printArray(arr, queue->queSize);\n    free(arr);\n}\n
    linkedlist_queue.zig
    // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u961f\u5217\nfn LinkedListQueue(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        front: ?*inc.ListNode(T) = null,                // \u5934\u8282\u70b9 front\n        rear: ?*inc.ListNode(T) = null,                 // \u5c3e\u8282\u70b9 rear\n        que_size: usize = 0,                            // \u961f\u5217\u7684\u957f\u5ea6\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u961f\u5217\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.front = null;\n            self.rear = null;\n            self.que_size = 0;\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.que_size;\n        }\n\n        // \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.size() == 0) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\n            return self.front.?.val;\n        }  \n\n        // \u5165\u961f\n        pub fn push(self: *Self, num: T) !void {\n            // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n            var node = try self.mem_allocator.create(inc.ListNode(T));\n            node.init(num);\n            // \u5982\u679c\u961f\u5217\u4e3a\u7a7a\uff0c\u5219\u4ee4\u5934\u3001\u5c3e\u8282\u70b9\u90fd\u6307\u5411\u8be5\u8282\u70b9\n            if (self.front == null) {\n                self.front = node;\n                self.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 {\n                self.rear.?.next = node;\n                self.rear = node;\n            }\n            self.que_size += 1;\n        } \n\n        // \u51fa\u961f\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            // \u5220\u9664\u5934\u8282\u70b9\n            self.front = self.front.?.next;\n            self.que_size -= 1;\n            return num;\n        } \n\n        // \u5c06\u94fe\u8868\u8f6c\u6362\u4e3a\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            var node = self.front;\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            while (i < res.len) : (i += 1) {\n                res[i] = node.?.val;\n                node = node.?.next;\n            }\n            return 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\"\"\"\n\n    def __init__(self, size: int):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._nums: list[int] = [0] * size  # \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n        self._front: int = 0  # \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n        self._size: int = 0  # \u961f\u5217\u957f\u5ea6\n\n    def capacity(self) -> int:\n        \"\"\"\u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\"\"\"\n        return len(self._nums)\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self._size == 0\n\n    def push(self, num: int):\n        \"\"\"\u5165\u961f\"\"\"\n        if self._size == self.capacity():\n            raise IndexError(\"\u961f\u5217\u5df2\u6ee1\")\n        # \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        # \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        rear: int = (self._front + self._size) % self.capacity()\n        # \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self._nums[rear] = num\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u961f\"\"\"\n        num: int = self.peek()\n        # \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        self._front = (self._front + 1) % self.capacity()\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u961f\u9996\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u961f\u5217\u4e3a\u7a7a\")\n        return self._nums[self._front]\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        res = [0] * self.size()\n        j: int = self._front\n        for i in range(self.size()):\n            res[i] = self._nums[(j % self.capacity())]\n            j += 1\n        return res\n
    array_queue.cpp
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n  private:\n    int *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;     // \u961f\u5217\u957f\u5ea6\n    int queCapacity; // \u961f\u5217\u5bb9\u91cf\n\n  public:\n    ArrayQueue(int capacity) {\n        // \u521d\u59cb\u5316\u6570\u7ec4\n        nums = new int[capacity];\n        queCapacity = capacity;\n        front = queSize = 0;\n    }\n\n    ~ArrayQueue() {\n        delete[] nums;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    int capacity() {\n        return queCapacity;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u961f */\n    void push(int num) {\n        if (queSize == queCapacity) {\n            cout << \"\u961f\u5217\u5df2\u6ee1\" << endl;\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        int rear = (front + queSize) % queCapacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    int pop() {\n        int num = peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % queCapacity;\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    int peek() {\n        if (isEmpty())\n            throw out_of_range(\"\u961f\u5217\u4e3a\u7a7a\");\n        return nums[front];\n    }\n\n    /* \u5c06\u6570\u7ec4\u8f6c\u5316\u4e3a Vector \u5e76\u8fd4\u56de */\n    vector<int> toVector() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        vector<int> arr(queSize);\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            arr[i] = nums[j % queCapacity];\n        }\n        return arr;\n    }\n};\n
    array_queue.java
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    private int[] nums; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private int front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private int queSize; // \u961f\u5217\u957f\u5ea6\n\n    public ArrayQueue(int capacity) {\n        nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    public int capacity() {\n        return nums.length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u5165\u961f */\n    public void push(int num) {\n        if (queSize == capacity()) {\n            System.out.println(\"\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        int rear = (front + queSize) % capacity();\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int pop() {\n        int num = peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % capacity();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return nums[front];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    public int[] toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[j % capacity()];\n        }\n        return res;\n    }\n}\n
    array_queue.cs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    int[] nums;  // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize; // \u961f\u5217\u957f\u5ea6\n\n    public ArrayQueue(int capacity) {\n        nums = new int[capacity];\n        front = queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    int Capacity() {\n        return nums.Length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    public int Size() {\n        return queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return queSize == 0;\n    }\n\n    /* \u5165\u961f */\n    public void Push(int num) {\n        if (queSize == Capacity()) {\n            Console.WriteLine(\"\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        int rear = (front + queSize) % Capacity();\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num;\n        queSize++;\n    }\n\n    /* \u51fa\u961f */\n    public int Pop() {\n        int num = Peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % Capacity();\n        queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return nums[front];\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    public int[] ToArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        int[] res = new int[queSize];\n        for (int i = 0, j = front; i < queSize; i++, j++) {\n            res[i] = nums[j % this.Capacity()];\n        }\n        return res;\n    }\n}\n
    array_queue.go
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntype arrayQueue struct {\n    nums        []int // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front       int   // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    queSize     int   // \u961f\u5217\u957f\u5ea6\n    queCapacity int   // \u961f\u5217\u5bb9\u91cf\uff08\u5373\u6700\u5927\u5bb9\u7eb3\u5143\u7d20\u6570\u91cf\uff09\n}\n\n/* \u521d\u59cb\u5316\u961f\u5217 */\nfunc newArrayQueue(queCapacity int) *arrayQueue {\n    return &arrayQueue{\n        nums:        make([]int, queCapacity),\n        queCapacity: queCapacity,\n        front:       0,\n        queSize:     0,\n    }\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nfunc (q *arrayQueue) size() int {\n    return q.queSize\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nfunc (q *arrayQueue) isEmpty() bool {\n    return q.queSize == 0\n}\n\n/* \u5165\u961f */\nfunc (q *arrayQueue) push(num int) {\n    // \u5f53 rear == queCapacity \u8868\u793a\u961f\u5217\u5df2\u6ee1\n    if q.queSize == q.queCapacity {\n        return\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n    rear := (q.front + q.queSize) % q.queCapacity\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    q.nums[rear] = num\n    q.queSize++\n}\n\n/* \u51fa\u961f */\nfunc (q *arrayQueue) pop() any {\n    num := q.peek()\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n    q.front = (q.front + 1) % q.queCapacity\n    q.queSize--\n    return num\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nfunc (q *arrayQueue) peek() any {\n    if q.isEmpty() {\n        return nil\n    }\n    return q.nums[q.front]\n}\n\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (q *arrayQueue) toSlice() []int {\n    rear := (q.front + q.queSize)\n    if rear >= q.queCapacity {\n        rear %= q.queCapacity\n        return append(q.nums[q.front:], q.nums[:rear]...)\n    }\n    return q.nums[q.front:rear]\n}\n
    array_queue.swift
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    private var nums: [Int] // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private var front = 0 // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private var queSize = 0 // \u961f\u5217\u957f\u5ea6\n\n    init(capacity: Int) {\n        // \u521d\u59cb\u5316\u6570\u7ec4\n        nums = Array(repeating: 0, count: capacity)\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    func capacity() -> Int {\n        nums.count\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        queSize\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        queSize == 0\n    }\n\n    /* \u5165\u961f */\n    func push(num: Int) {\n        if size() == capacity() {\n            print(\"\u961f\u5217\u5df2\u6ee1\")\n            return\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        let rear = (front + queSize) % capacity()\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        nums[rear] = num\n        queSize += 1\n    }\n\n    /* \u51fa\u961f */\n    @discardableResult\n    func pop() -> Int {\n        let num = peek()\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        front = (front + 1) % capacity()\n        queSize -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u961f\u5217\u4e3a\u7a7a\")\n        }\n        return nums[front]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    func toArray() -> [Int] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        var res = Array(repeating: 0, count: queSize)\n        for (i, j) in sequence(first: (0, front), next: { $0 < self.queSize - 1 ? ($0 + 1, $1 + 1) : nil }) {\n            res[i] = nums[j % capacity()]\n        }\n        return 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\n\n    constructor(capacity) {\n        this.#nums = new Array(capacity);\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    get capacity() {\n        return this.#nums.length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#queSize === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num) {\n        if (this.size === this.capacity) {\n            console.log('\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        const rear = (this.#front + this.size) % this.capacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.#nums[rear] = num;\n        this.#queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop() {\n        const num = this.peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        this.#front = (this.#front + 1) % this.capacity;\n        this.#queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek() {\n        if (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.#nums[this.#front];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray() {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(this.size);\n        for (let i = 0, j = this.#front; i < this.size; i++, j++) {\n            arr[i] = this.#nums[j % this.capacity];\n        }\n        return arr;\n    }\n}\n
    array_queue.ts
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n    private nums: number[]; // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    private front: number; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    private queSize: number; // \u961f\u5217\u957f\u5ea6\n\n    constructor(capacity: number) {\n        this.nums = new Array(capacity);\n        this.front = this.queSize = 0;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    get capacity(): number {\n        return this.nums.length;\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.queSize;\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.queSize === 0;\n    }\n\n    /* \u5165\u961f */\n    push(num: number): void {\n        if (this.size === this.capacity) {\n            console.log('\u961f\u5217\u5df2\u6ee1');\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        const rear = (this.front + this.queSize) % this.capacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        this.nums[rear] = num;\n        this.queSize++;\n    }\n\n    /* \u51fa\u961f */\n    pop(): number {\n        const num = this.peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        this.front = (this.front + 1) % this.capacity;\n        this.queSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    peek(): number {\n        if (this.isEmpty()) throw new Error('\u961f\u5217\u4e3a\u7a7a');\n        return this.nums[this.front];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray(): number[] {\n        // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n        const arr = new Array(this.size);\n        for (let i = 0, j = this.front; i < this.size; i++, j++) {\n            arr[i] = this.nums[j % this.capacity];\n        }\n        return arr;\n    }\n}\n
    array_queue.dart
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nclass ArrayQueue {\n  late List<int> _nums; // \u7528\u4e8e\u50a8\u5b58\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n  late int _front; // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n  late int _queSize; // \u961f\u5217\u957f\u5ea6\n\n  ArrayQueue(int capacity) {\n    _nums = List.filled(capacity, 0);\n    _front = _queSize = 0;\n  }\n\n  /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n  int capaCity() {\n    return _nums.length;\n  }\n\n  /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n  int size() {\n    return _queSize;\n  }\n\n  /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _queSize == 0;\n  }\n\n  /* \u5165\u961f */\n  void push(int _num) {\n    if (_queSize == capaCity()) {\n      throw Exception(\"\u961f\u5217\u5df2\u6ee1\");\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n    int rear = (_front + _queSize) % capaCity();\n    // \u5c06 _num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    _nums[rear] = _num;\n    _queSize++;\n  }\n\n  /* \u51fa\u961f */\n  int pop() {\n    int _num = peek();\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n    _front = (_front + 1) % capaCity();\n    _queSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n  int peek() {\n    if (isEmpty()) {\n      throw Exception(\"\u961f\u5217\u4e3a\u7a7a\");\n    }\n    return _nums[_front];\n  }\n\n  /* \u8fd4\u56de Array */\n  List<int> toArray() {\n    // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n    final List<int> res = List.filled(_queSize, 0);\n    for (int i = 0, j = _front; i < _queSize; i++, j++) {\n      res[i] = _nums[j % capaCity()];\n    }\n    return res;\n  }\n}\n
    array_queue.rs
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\nstruct ArrayQueue {\n    nums: Vec<i32>,     // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    front: i32,         // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    que_size: i32,      // \u961f\u5217\u957f\u5ea6\n    que_capacity: i32,  // \u961f\u5217\u5bb9\u91cf\n}\n\nimpl ArrayQueue {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(capacity: i32) -> ArrayQueue {\n        ArrayQueue {\n            nums: vec![0; capacity as usize],\n            front: 0,\n            que_size: 0,\n            que_capacity: capacity,\n        }\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\n    fn capacity(&self) -> i32 {\n        self.que_capacity\n    }\n\n    /* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\n    fn size(&self) -> i32 {\n        self.que_size\n    }\n\n    /* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\n    fn is_empty(&self) -> bool {\n        self.que_size == 0\n    }\n\n    /* \u5165\u961f */\n    fn push(&mut self, num: i32) {\n        if self.que_size == self.capacity() {\n            println!(\"\u961f\u5217\u5df2\u6ee1\");\n            return;\n        }\n        // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n        // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n        let rear = (self.front + self.que_size) % self.que_capacity;\n        // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n        self.nums[rear as usize] = num;\n        self.que_size += 1;\n    }\n\n    /* \u51fa\u961f */\n    fn pop(&mut self) -> i32 {\n        let num = self.peek();\n        // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n        self.front = (self.front + 1) % self.que_capacity;\n        self.que_size -= 1;\n        num\n    }\n\n    /* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\n    fn peek(&self) -> i32 {\n        if self.is_empty() {\n            panic!(\"index out of bounds\");\n        }\n        self.nums[self.front as usize]\n    }\n\n    /* \u8fd4\u56de\u6570\u7ec4 */\n    fn to_vector(&self) -> Vec<i32> {\n        let cap = self.que_capacity;\n        let mut j = self.front;\n        let mut arr = vec![0; self.que_size as usize];\n        for i in 0..self.que_size {\n            arr[i as usize] = self.nums[(j % cap) as usize];\n            j += 1;\n        }\n        arr\n    }\n}\n
    array_queue.c
    /* \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217 */\ntypedef struct {\n    int *nums;       // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4\n    int front;       // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n    int queSize;     // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\n    int queCapacity; // \u961f\u5217\u5bb9\u91cf\n} ArrayQueue;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayQueue *newArrayQueue(int capacity) {\n    ArrayQueue *queue = (ArrayQueue *)malloc(sizeof(ArrayQueue));\n    // \u521d\u59cb\u5316\u6570\u7ec4\n    queue->queCapacity = capacity;\n    queue->nums = (int *)malloc(sizeof(int) * queue->queCapacity);\n    queue->front = queue->queSize = 0;\n    return queue;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayQueue(ArrayQueue *queue) {\n    free(queue->nums);\n    free(queue);\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf */\nint capacity(ArrayQueue *queue) {\n    return queue->queCapacity;\n}\n\n/* \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6 */\nint size(ArrayQueue *queue) {\n    return queue->queSize;\n}\n\n/* \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a */\nbool empty(ArrayQueue *queue) {\n    return queue->queSize == 0;\n}\n\n/* \u8bbf\u95ee\u961f\u9996\u5143\u7d20 */\nint peek(ArrayQueue *queue) {\n    assert(size(queue) != 0);\n    return queue->nums[queue->front];\n}\n\n/* \u5165\u961f */\nvoid push(ArrayQueue *queue, int num) {\n    if (size(queue) == capacity(queue)) {\n        printf(\"\u961f\u5217\u5df2\u6ee1\\r\\n\");\n        return;\n    }\n    // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n    // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n    int rear = (queue->front + queue->queSize) % queue->queCapacity;\n    // \u5c06 num \u6dfb\u52a0\u81f3\u961f\u5c3e\n    queue->nums[rear] = num;\n    queue->queSize++;\n}\n\n/* \u51fa\u961f */\nint pop(ArrayQueue *queue) {\n    int num = peek(queue);\n    // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n    queue->front = (queue->front + 1) % queue->queCapacity;\n    queue->queSize--;\n    return num;\n}\n
    array_queue.zig
    // \u57fa\u4e8e\u73af\u5f62\u6570\u7ec4\u5b9e\u73b0\u7684\u961f\u5217\nfn ArrayQueue(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        nums: []T = undefined,                          // \u7528\u4e8e\u5b58\u50a8\u961f\u5217\u5143\u7d20\u7684\u6570\u7ec4     \n        cap: usize = 0,                                 // \u961f\u5217\u5bb9\u91cf\n        front: usize = 0,                               // \u961f\u9996\u6307\u9488\uff0c\u6307\u5411\u961f\u9996\u5143\u7d20\n        queSize: usize = 0,                             // \u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e + 1\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,   // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6570\u7ec4\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator, cap: usize) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.cap = cap;\n            self.nums = try self.mem_allocator.alloc(T, self.cap);\n            @memset(self.nums, @as(T, 0));\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u961f\u5217\u7684\u5bb9\u91cf\n        pub fn capacity(self: *Self) usize {\n            return self.cap;\n        }\n\n        // \u83b7\u53d6\u961f\u5217\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.queSize;\n        }\n\n        // \u5224\u65ad\u961f\u5217\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.queSize == 0;\n        }\n\n        // \u5165\u961f\n        pub fn push(self: *Self, num: T) !void {\n            if (self.size() == self.capacity()) {\n                std.debug.print(\"\u961f\u5217\u5df2\u6ee1\\n\", .{});\n                return;\n            }\n            // \u8ba1\u7b97\u961f\u5c3e\u6307\u9488\uff0c\u6307\u5411\u961f\u5c3e\u7d22\u5f15 + 1\n            // \u901a\u8fc7\u53d6\u4f59\u64cd\u4f5c\u5b9e\u73b0 rear \u8d8a\u8fc7\u6570\u7ec4\u5c3e\u90e8\u540e\u56de\u5230\u5934\u90e8\n            var rear = (self.front + self.queSize) % self.capacity();\n            // \u5728\u5c3e\u8282\u70b9\u540e\u6dfb\u52a0 num\n            self.nums[rear] = num;\n            self.queSize += 1;\n        } \n\n        // \u51fa\u961f\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            // \u961f\u9996\u6307\u9488\u5411\u540e\u79fb\u52a8\u4e00\u4f4d\uff0c\u82e5\u8d8a\u8fc7\u5c3e\u90e8\uff0c\u5219\u8fd4\u56de\u5230\u6570\u7ec4\u5934\u90e8\n            self.front = (self.front + 1) % self.capacity();\n            self.queSize -= 1;\n            return num;\n        } \n\n        // \u8bbf\u95ee\u961f\u9996\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u961f\u5217\u4e3a\u7a7a\");\n            return self.nums[self.front];\n        } \n\n        // \u8fd4\u56de\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            // \u4ec5\u8f6c\u6362\u6709\u6548\u957f\u5ea6\u8303\u56f4\u5185\u7684\u5217\u8868\u5143\u7d20\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            var j: usize = self.front;\n            while (i < self.size()) : ({ i += 1; j += 1; }) {\n                res[i] = self.nums[j % self.capacity()];\n            }\n            return 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\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\u7684\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\n# \u5143\u7d20\u5165\u6808\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n\n# \u8bbf\u95ee\u6808\u9876\u5143\u7d20\npeek: int = stack[-1]\n\n# \u5143\u7d20\u51fa\u6808\npop: int = stack.pop()\n\n# \u83b7\u53d6\u6808\u7684\u957f\u5ea6\nsize: int = len(stack)\n\n# \u5224\u65ad\u662f\u5426\u4e3a\u7a7a\nis_empty: bool = len(stack) == 0\n
    stack.cpp
    /* \u521d\u59cb\u5316\u6808 */\nstack<int> stack;\n\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint top = stack.top();\n\n/* \u5143\u7d20\u51fa\u6808 */\nstack.pop(); // \u65e0\u8fd4\u56de\u503c\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nbool empty = stack.empty();\n
    stack.java
    /* \u521d\u59cb\u5316\u6808 */\nStack<Integer> stack = new Stack<>();\n\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.peek();\n\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.size();\n\n/* \u5224\u65ad\u662f\u5426\u4e3a\u7a7a */\nboolean isEmpty = stack.isEmpty();\n
    stack.cs
    /* \u521d\u59cb\u5316\u6808 */\nStack<int> stack = new();\n\n/* \u5143\u7d20\u5165\u6808 */\nstack.Push(1);\nstack.Push(3);\nstack.Push(2);\nstack.Push(5);\nstack.Push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.Peek();\n\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.Pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.Count;\n\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\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\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\npeek := stack[len(stack)-1]\n\n/* \u5143\u7d20\u51fa\u6808 */\npop := stack[len(stack)-1]\nstack = stack[:len(stack)-1]\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nsize := len(stack)\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.append(1)\nstack.append(3)\nstack.append(2)\nstack.append(5)\nstack.append(4)\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet peek = stack.last!\n\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.removeLast()\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.count\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length-1];\n\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nconst peek = stack[stack.length - 1];\n\n/* \u5143\u7d20\u51fa\u6808 */\nconst pop = stack.pop();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nconst size = stack.length;\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.add(1);\nstack.add(3);\nstack.add(2);\nstack.add(5);\nstack.add(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek = stack.last;\n\n/* \u5143\u7d20\u51fa\u6808 */\nint pop = stack.removeLast();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size = stack.length;\n\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\n/* \u5143\u7d20\u5165\u6808 */\nstack.push(1);\nstack.push(3);\nstack.push(2);\nstack.push(5);\nstack.push(4);\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nlet top = stack.last().unwrap();\n\n/* \u5143\u7d20\u51fa\u6808 */\nlet pop = stack.pop().unwrap();\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nlet size = stack.len();\n\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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._peek: ListNode | None = None\n        self._size: int = 0\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return not self._peek\n\n    def push(self, val: int):\n        \"\"\"\u5165\u6808\"\"\"\n        node = ListNode(val)\n        node.next = self._peek\n        self._peek = node\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u6808\"\"\"\n        num = self.peek()\n        self._peek = self._peek.next\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u6808\u4e3a\u7a7a\")\n        return self._peek.val\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8f6c\u5316\u4e3a\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        arr = []\n        node = self._peek\n        while node:\n            arr.append(node.val)\n            node = node.next\n        arr.reverse()\n        return arr\n
    linkedlist_stack.cpp
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n  private:\n    ListNode *stackTop; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    int stkSize;        // \u6808\u7684\u957f\u5ea6\n\n  public:\n    LinkedListStack() {\n        stackTop = nullptr;\n        stkSize = 0;\n    }\n\n    ~LinkedListStack() {\n        // \u904d\u5386\u94fe\u8868\u5220\u9664\u8282\u70b9\uff0c\u91ca\u653e\u5185\u5b58\n        freeMemoryLinkedList(stackTop);\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    int size() {\n        return stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    void push(int num) {\n        ListNode *node = new ListNode(num);\n        node->next = stackTop;\n        stackTop = node;\n        stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    int pop() {\n        int num = top();\n        ListNode *tmp = stackTop;\n        stackTop = stackTop->next;\n        // \u91ca\u653e\u5185\u5b58\n        delete tmp;\n        stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    int top() {\n        if (isEmpty())\n            throw out_of_range(\"\u6808\u4e3a\u7a7a\");\n        return stackTop->val;\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    vector<int> toVector() {\n        ListNode *node = stackTop;\n        vector<int> res(size());\n        for (int i = res.size() - 1; i >= 0; i--) {\n            res[i] = node->val;\n            node = node->next;\n        }\n        return res;\n    }\n};\n
    linkedlist_stack.java
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    private ListNode stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    private int stkSize = 0; // \u6808\u7684\u957f\u5ea6\n\n    public LinkedListStack() {\n        stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int size() {\n        return stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void push(int num) {\n        ListNode node = new ListNode(num);\n        node.next = stackPeek;\n        stackPeek = node;\n        stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    public int pop() {\n        int num = peek();\n        stackPeek = stackPeek.next;\n        stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return stackPeek.val;\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] toArray() {\n        ListNode node = stackPeek;\n        int[] res = new int[size()];\n        for (int i = res.length - 1; i >= 0; i--) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_stack.cs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    ListNode? stackPeek;  // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    int stkSize = 0;   // \u6808\u7684\u957f\u5ea6\n\n    public LinkedListStack() {\n        stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int Size() {\n        return stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void Push(int num) {\n        ListNode node = new(num) {\n            next = stackPeek\n        };\n        stackPeek = node;\n        stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    public int Pop() {\n        int num = Peek();\n        stackPeek = stackPeek!.next;\n        stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return stackPeek!.val;\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] ToArray() {\n        if (stackPeek == null)\n            return [];\n\n        ListNode? node = stackPeek;\n        int[] res = new int[Size()];\n        for (int i = res.Length - 1; i >= 0; i--) {\n            res[i] = node!.val;\n            node = node.next;\n        }\n        return 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\n    data *list.List\n}\n\n/* \u521d\u59cb\u5316\u6808 */\nfunc newLinkedListStack() *linkedListStack {\n    return &linkedListStack{\n        data: list.New(),\n    }\n}\n\n/* \u5165\u6808 */\nfunc (s *linkedListStack) push(value int) {\n    s.data.PushBack(value)\n}\n\n/* \u51fa\u6808 */\nfunc (s *linkedListStack) pop() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    s.data.Remove(e)\n    return e.Value\n}\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nfunc (s *linkedListStack) peek() any {\n    if s.isEmpty() {\n        return nil\n    }\n    e := s.data.Back()\n    return e.Value\n}\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nfunc (s *linkedListStack) size() int {\n    return s.data.Len()\n}\n\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *linkedListStack) isEmpty() bool {\n    return s.data.Len() == 0\n}\n\n/* \u83b7\u53d6 List \u7528\u4e8e\u6253\u5370 */\nfunc (s *linkedListStack) toList() *list.List {\n    return s.data\n}\n
    linkedlist_stack.swift
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    private var _peek: ListNode? // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    private var _size = 0 // \u6808\u7684\u957f\u5ea6\n\n    init() {}\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        _size\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        size() == 0\n    }\n\n    /* \u5165\u6808 */\n    func push(num: Int) {\n        let node = ListNode(x: num)\n        node.next = _peek\n        _peek = node\n        _size += 1\n    }\n\n    /* \u51fa\u6808 */\n    @discardableResult\n    func pop() -> Int {\n        let num = peek()\n        _peek = _peek?.next\n        _size -= 1\n        return num\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u6808\u4e3a\u7a7a\")\n        }\n        return _peek!.val\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    func toArray() -> [Int] {\n        var node = _peek\n        var res = Array(repeating: 0, count: _size)\n        for i in sequence(first: res.count - 1, next: { $0 >= 0 + 1 ? $0 - 1 : nil }) {\n            res[i] = node!.val\n            node = node?.next\n        }\n        return 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\n\n    constructor() {\n        this.#stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.size === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num) {\n        const node = new ListNode(num);\n        node.next = this.#stackPeek;\n        this.#stackPeek = node;\n        this.#stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    pop() {\n        const num = this.peek();\n        this.#stackPeek = this.#stackPeek.next;\n        this.#stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    peek() {\n        if (!this.#stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.#stackPeek.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray() {\n        let node = this.#stackPeek;\n        const res = new Array(this.size);\n        for (let i = res.length - 1; i >= 0; i--) {\n            res[i] = node.val;\n            node = node.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_stack.ts
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n    private stackPeek: ListNode | null; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    private stkSize: number = 0; // \u6808\u7684\u957f\u5ea6\n\n    constructor() {\n        this.stackPeek = null;\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.stkSize;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.size === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num: number): void {\n        const node = new ListNode(num);\n        node.next = this.stackPeek;\n        this.stackPeek = node;\n        this.stkSize++;\n    }\n\n    /* \u51fa\u6808 */\n    pop(): number {\n        const num = this.peek();\n        if (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\n        this.stackPeek = this.stackPeek.next;\n        this.stkSize--;\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    peek(): number {\n        if (!this.stackPeek) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.stackPeek.val;\n    }\n\n    /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    toArray(): number[] {\n        let node = this.stackPeek;\n        const res = new Array<number>(this.size);\n        for (let i = res.length - 1; i >= 0; i--) {\n            res[i] = node!.val;\n            node = node!.next;\n        }\n        return res;\n    }\n}\n
    linkedlist_stack.dart
    /* \u57fa\u4e8e\u94fe\u8868\u7c7b\u5b9e\u73b0\u7684\u6808 */\nclass LinkedListStack {\n  ListNode? _stackPeek; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n  int _stkSize = 0; // \u6808\u7684\u957f\u5ea6\n\n  LinkedListStack() {\n    _stackPeek = null;\n  }\n\n  /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n  int size() {\n    return _stkSize;\n  }\n\n  /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _stkSize == 0;\n  }\n\n  /* \u5165\u6808 */\n  void push(int _num) {\n    final ListNode node = ListNode(_num);\n    node.next = _stackPeek;\n    _stackPeek = node;\n    _stkSize++;\n  }\n\n  /* \u51fa\u6808 */\n  int pop() {\n    final int _num = peek();\n    _stackPeek = _stackPeek!.next;\n    _stkSize--;\n    return _num;\n  }\n\n  /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n  int peek() {\n    if (_stackPeek == null) {\n      throw Exception(\"\u6808\u4e3a\u7a7a\");\n    }\n    return _stackPeek!.val;\n  }\n\n  /* \u5c06\u94fe\u8868\u8f6c\u5316\u4e3a List \u5e76\u8fd4\u56de */\n  List<int> toList() {\n    ListNode? node = _stackPeek;\n    List<int> list = [];\n    while (node != null) {\n      list.add(node.val);\n      node = node.next;\n    }\n    list = list.reversed.toList();\n    return list;\n  }\n}\n
    linkedlist_stack.rs
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\n#[allow(dead_code)]\npub struct LinkedListStack<T> {\n    stack_peek: Option<Rc<RefCell<ListNode<T>>>>,   // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    stk_size: usize,                                // \u6808\u7684\u957f\u5ea6\n}\n\nimpl<T: Copy> LinkedListStack<T> {\n    pub fn new() -> Self {\n        Self {\n            stack_peek: None,\n            stk_size: 0,\n        }\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    pub fn size(&self) -> usize {\n        return self.stk_size;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    pub fn is_empty(&self) -> bool {\n        return self.size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    pub fn push(&mut self, num: T) {\n        let node = ListNode::new(num);\n        node.borrow_mut().next = self.stack_peek.take();\n        self.stack_peek = Some(node);\n        self.stk_size += 1;\n    }\n\n    /* \u51fa\u6808 */\n    pub fn pop(&mut self) -> Option<T> {\n        self.stack_peek.take().map(|old_head| {\n            match old_head.borrow_mut().next.take() {\n                Some(new_head) => {\n                    self.stack_peek = Some(new_head);\n                }\n                None => {\n                    self.stack_peek = None;\n                }\n            }\n            self.stk_size -= 1;\n            Rc::try_unwrap(old_head).ok().unwrap().into_inner().val\n        })\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    pub fn peek(&self) -> Option<&Rc<RefCell<ListNode<T>>>> {\n        self.stack_peek.as_ref()\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    pub fn to_array(&self, head: Option<&Rc<RefCell<ListNode<T>>>>) -> Vec<T> {\n        if let Some(node) = head {\n            let mut nums = self.to_array(node.borrow().next.as_ref());\n            nums.push(node.borrow().val);\n            return nums;\n        }\n        return Vec::new();\n    }\n}\n
    linkedlist_stack.c
    /* \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\n    ListNode *top; // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n    int size;      // \u6808\u7684\u957f\u5ea6\n} LinkedListStack;\n\n/* \u6784\u9020\u51fd\u6570 */\nLinkedListStack *newLinkedListStack() {\n    LinkedListStack *s = malloc(sizeof(LinkedListStack));\n    s->top = NULL;\n    s->size = 0;\n    return s;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delLinkedListStack(LinkedListStack *s) {\n    while (s->top) {\n        ListNode *n = s->top->next;\n        free(s->top);\n        s->top = n;\n    }\n    free(s);\n}\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(LinkedListStack *s) {\n    return s->size;\n}\n\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(LinkedListStack *s) {\n    return size(s) == 0;\n}\n\n/* \u5165\u6808 */\nvoid push(LinkedListStack *s, int num) {\n    ListNode *node = (ListNode *)malloc(sizeof(ListNode));\n    node->next = s->top; // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6307\u9488\u57df\n    node->val = num;     // \u66f4\u65b0\u65b0\u52a0\u8282\u70b9\u6570\u636e\u57df\n    s->top = node;       // \u66f4\u65b0\u6808\u9876\n    s->size++;           // \u66f4\u65b0\u6808\u5927\u5c0f\n}\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(LinkedListStack *s) {\n    if (s->size == 0) {\n        printf(\"\u6808\u4e3a\u7a7a\\n\");\n        return INT_MAX;\n    }\n    return s->top->val;\n}\n\n/* \u51fa\u6808 */\nint pop(LinkedListStack *s) {\n    int val = peek(s);\n    ListNode *tmp = s->top;\n    s->top = s->top->next;\n    // \u91ca\u653e\u5185\u5b58\n    free(tmp);\n    s->size--;\n    return val;\n}\n
    linkedlist_stack.zig
    // \u57fa\u4e8e\u94fe\u8868\u5b9e\u73b0\u7684\u6808\nfn LinkedListStack(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        stack_top: ?*inc.ListNode(T) = null,             // \u5c06\u5934\u8282\u70b9\u4f5c\u4e3a\u6808\u9876\n        stk_size: usize = 0,                             // \u6808\u7684\u957f\u5ea6\n        mem_arena: ?std.heap.ArenaAllocator = null,\n        mem_allocator: std.mem.Allocator = undefined,    // \u5185\u5b58\u5206\u914d\u5668\n\n        // \u6784\u9020\u51fd\u6570\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) !void {\n            if (self.mem_arena == null) {\n                self.mem_arena = std.heap.ArenaAllocator.init(allocator);\n                self.mem_allocator = self.mem_arena.?.allocator();\n            }\n            self.stack_top = null;\n            self.stk_size = 0;\n        }\n\n        // \u6790\u6784\u51fd\u6570\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.mem_arena == null) return;\n            self.mem_arena.?.deinit();\n        }\n\n        // \u83b7\u53d6\u6808\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.stk_size;\n        }\n\n        // \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u8bbf\u95ee\u6808\u9876\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.size() == 0) @panic(\"\u6808\u4e3a\u7a7a\");\n            return self.stack_top.?.val;\n        }  \n\n        // \u5165\u6808\n        pub fn push(self: *Self, num: T) !void {\n            var node = try self.mem_allocator.create(inc.ListNode(T));\n            node.init(num);\n            node.next = self.stack_top;\n            self.stack_top = node;\n            self.stk_size += 1;\n        } \n\n        // \u51fa\u6808\n        pub fn pop(self: *Self) T {\n            var num = self.peek();\n            self.stack_top = self.stack_top.?.next;\n            self.stk_size -= 1;\n            return num;\n        } \n\n        // \u5c06\u6808\u8f6c\u6362\u4e3a\u6570\u7ec4\n        pub fn toArray(self: *Self) ![]T {\n            var node = self.stack_top;\n            var res = try self.mem_allocator.alloc(T, self.size());\n            @memset(res, @as(T, 0));\n            var i: usize = 0;\n            while (i < res.len) : (i += 1) {\n                res[res.len - i - 1] = node.?.val;\n                node = node.?.next;\n            }\n            return 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\"\"\"\n\n    def __init__(self):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._stack: list[int] = []\n\n    def size(self) -> int:\n        \"\"\"\u83b7\u53d6\u6808\u7684\u957f\u5ea6\"\"\"\n        return len(self._stack)\n\n    def is_empty(self) -> bool:\n        \"\"\"\u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\"\"\"\n        return self._stack == []\n\n    def push(self, item: int):\n        \"\"\"\u5165\u6808\"\"\"\n        self._stack.append(item)\n\n    def pop(self) -> int:\n        \"\"\"\u51fa\u6808\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u6808\u4e3a\u7a7a\")\n        return self._stack.pop()\n\n    def peek(self) -> int:\n        \"\"\"\u8bbf\u95ee\u6808\u9876\u5143\u7d20\"\"\"\n        if self.is_empty():\n            raise IndexError(\"\u6808\u4e3a\u7a7a\")\n        return self._stack[-1]\n\n    def to_list(self) -> list[int]:\n        \"\"\"\u8fd4\u56de\u5217\u8868\u7528\u4e8e\u6253\u5370\"\"\"\n        return self._stack\n
    array_stack.cpp
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n  private:\n    vector<int> stack;\n\n  public:\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    int size() {\n        return stack.size();\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    bool isEmpty() {\n        return stack.size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    void push(int num) {\n        stack.push_back(num);\n    }\n\n    /* \u51fa\u6808 */\n    int pop() {\n        int num = top();\n        stack.pop_back();\n        return num;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    int top() {\n        if (isEmpty())\n            throw out_of_range(\"\u6808\u4e3a\u7a7a\");\n        return stack.back();\n    }\n\n    /* \u8fd4\u56de Vector */\n    vector<int> toVector() {\n        return stack;\n    }\n};\n
    array_stack.java
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    private ArrayList<Integer> stack;\n\n    public ArrayStack() {\n        // \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\n        stack = new ArrayList<>();\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int size() {\n        return stack.size();\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public boolean isEmpty() {\n        return size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void push(int num) {\n        stack.add(num);\n    }\n\n    /* \u51fa\u6808 */\n    public int pop() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return stack.remove(size() - 1);\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int peek() {\n        if (isEmpty())\n            throw new IndexOutOfBoundsException();\n        return stack.get(size() - 1);\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public Object[] toArray() {\n        return stack.toArray();\n    }\n}\n
    array_stack.cs
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    List<int> stack;\n    public ArrayStack() {\n        // \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\n        stack = [];\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    public int Size() {\n        return stack.Count;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    public bool IsEmpty() {\n        return Size() == 0;\n    }\n\n    /* \u5165\u6808 */\n    public void Push(int num) {\n        stack.Add(num);\n    }\n\n    /* \u51fa\u6808 */\n    public int Pop() {\n        if (IsEmpty())\n            throw new Exception();\n        var val = Peek();\n        stack.RemoveAt(Size() - 1);\n        return val;\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    public int Peek() {\n        if (IsEmpty())\n            throw new Exception();\n        return stack[Size() - 1];\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    public int[] ToArray() {\n        return [.. stack];\n    }\n}\n
    array_stack.go
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntype arrayStack struct {\n    data []int // \u6570\u636e\n}\n\n/* \u521d\u59cb\u5316\u6808 */\nfunc newArrayStack() *arrayStack {\n    return &arrayStack{\n        // \u8bbe\u7f6e\u6808\u7684\u957f\u5ea6\u4e3a 0\uff0c\u5bb9\u91cf\u4e3a 16\n        data: make([]int, 0, 16),\n    }\n}\n\n/* \u6808\u7684\u957f\u5ea6 */\nfunc (s *arrayStack) size() int {\n    return len(s.data)\n}\n\n/* \u6808\u662f\u5426\u4e3a\u7a7a */\nfunc (s *arrayStack) isEmpty() bool {\n    return s.size() == 0\n}\n\n/* \u5165\u6808 */\nfunc (s *arrayStack) push(v int) {\n    // \u5207\u7247\u4f1a\u81ea\u52a8\u6269\u5bb9\n    s.data = append(s.data, v)\n}\n\n/* \u51fa\u6808 */\nfunc (s *arrayStack) pop() any {\n    val := s.peek()\n    s.data = s.data[:len(s.data)-1]\n    return val\n}\n\n/* \u83b7\u53d6\u6808\u9876\u5143\u7d20 */\nfunc (s *arrayStack) peek() any {\n    if s.isEmpty() {\n        return nil\n    }\n    val := s.data[len(s.data)-1]\n    return val\n}\n\n/* \u83b7\u53d6 Slice \u7528\u4e8e\u6253\u5370 */\nfunc (s *arrayStack) toSlice() []int {\n    return s.data\n}\n
    array_stack.swift
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    private var stack: [Int]\n\n    init() {\n        // \u521d\u59cb\u5316\u5217\u8868\uff08\u52a8\u6001\u6570\u7ec4\uff09\n        stack = []\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    func size() -> Int {\n        stack.count\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    func isEmpty() -> Bool {\n        stack.isEmpty\n    }\n\n    /* \u5165\u6808 */\n    func push(num: Int) {\n        stack.append(num)\n    }\n\n    /* \u51fa\u6808 */\n    @discardableResult\n    func pop() -> Int {\n        if isEmpty() {\n            fatalError(\"\u6808\u4e3a\u7a7a\")\n        }\n        return stack.removeLast()\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    func peek() -> Int {\n        if isEmpty() {\n            fatalError(\"\u6808\u4e3a\u7a7a\")\n        }\n        return stack.last!\n    }\n\n    /* \u5c06 List \u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n    func toArray() -> [Int] {\n        stack\n    }\n}\n
    array_stack.js
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    #stack;\n    constructor() {\n        this.#stack = [];\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size() {\n        return this.#stack.length;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty() {\n        return this.#stack.length === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num) {\n        this.#stack.push(num);\n    }\n\n    /* \u51fa\u6808 */\n    pop() {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.#stack.pop();\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    top() {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.#stack[this.#stack.length - 1];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray() {\n        return this.#stack;\n    }\n}\n
    array_stack.ts
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n    private stack: number[];\n    constructor() {\n        this.stack = [];\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    get size(): number {\n        return this.stack.length;\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    isEmpty(): boolean {\n        return this.stack.length === 0;\n    }\n\n    /* \u5165\u6808 */\n    push(num: number): void {\n        this.stack.push(num);\n    }\n\n    /* \u51fa\u6808 */\n    pop(): number | undefined {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.stack.pop();\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    top(): number | undefined {\n        if (this.isEmpty()) throw new Error('\u6808\u4e3a\u7a7a');\n        return this.stack[this.stack.length - 1];\n    }\n\n    /* \u8fd4\u56de Array */\n    toArray() {\n        return this.stack;\n    }\n}\n
    array_stack.dart
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nclass ArrayStack {\n  late List<int> _stack;\n  ArrayStack() {\n    _stack = [];\n  }\n\n  /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n  int size() {\n    return _stack.length;\n  }\n\n  /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n  bool isEmpty() {\n    return _stack.isEmpty;\n  }\n\n  /* \u5165\u6808 */\n  void push(int _num) {\n    _stack.add(_num);\n  }\n\n  /* \u51fa\u6808 */\n  int pop() {\n    if (isEmpty()) {\n      throw Exception(\"\u6808\u4e3a\u7a7a\");\n    }\n    return _stack.removeLast();\n  }\n\n  /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n  int peek() {\n    if (isEmpty()) {\n      throw Exception(\"\u6808\u4e3a\u7a7a\");\n    }\n    return _stack.last;\n  }\n\n  /* \u5c06\u6808\u8f6c\u5316\u4e3a Array \u5e76\u8fd4\u56de */\n  List<int> toArray() => _stack;\n}\n
    array_stack.rs
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\nstruct ArrayStack<T> {\n    stack: Vec<T>,\n}\n\nimpl<T> ArrayStack<T> {\n    /* \u521d\u59cb\u5316\u6808 */\n    fn new() -> ArrayStack<T> {\n        ArrayStack::<T> { stack: Vec::<T>::new() }\n    }\n\n    /* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\n    fn size(&self) -> usize {\n        self.stack.len()\n    }\n\n    /* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\n    fn is_empty(&self) -> bool {\n        self.size() == 0\n    }\n\n    /* \u5165\u6808 */\n    fn push(&mut self, num: T) {\n        self.stack.push(num);\n    }\n\n    /* \u51fa\u6808 */\n    fn pop(&mut self) -> Option<T> {\n        match self.stack.pop() {\n            Some(num) => Some(num),\n            None => None,\n        }\n    }\n\n    /* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\n    fn peek(&self) -> Option<&T> {\n        if self.is_empty() { panic!(\"\u6808\u4e3a\u7a7a\") };\n        self.stack.last()\n    }\n\n    /* \u8fd4\u56de &Vec */\n    fn to_array(&self) -> &Vec<T> {\n        &self.stack\n    }\n}\n
    array_stack.c
    /* \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808 */\ntypedef struct {\n    int *data;\n    int size;\n} ArrayStack;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayStack *newArrayStack() {\n    ArrayStack *stack = malloc(sizeof(ArrayStack));\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5927\u5bb9\u91cf\uff0c\u907f\u514d\u6269\u5bb9\n    stack->data = malloc(sizeof(int) * MAX_SIZE);\n    stack->size = 0;\n    return stack;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayStack(ArrayStack *stack) {\n    free(stack->data);\n    free(stack);\n}\n\n/* \u83b7\u53d6\u6808\u7684\u957f\u5ea6 */\nint size(ArrayStack *stack) {\n    return stack->size;\n}\n\n/* \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a */\nbool isEmpty(ArrayStack *stack) {\n    return stack->size == 0;\n}\n\n/* \u5165\u6808 */\nvoid push(ArrayStack *stack, int num) {\n    if (stack->size == MAX_SIZE) {\n        printf(\"\u6808\u5df2\u6ee1\\n\");\n        return;\n    }\n    stack->data[stack->size] = num;\n    stack->size++;\n}\n\n/* \u8bbf\u95ee\u6808\u9876\u5143\u7d20 */\nint peek(ArrayStack *stack) {\n    if (stack->size == 0) {\n        printf(\"\u6808\u4e3a\u7a7a\\n\");\n        return INT_MAX;\n    }\n    return stack->data[stack->size - 1];\n}\n\n/* \u51fa\u6808 */\nint pop(ArrayStack *stack) {\n    int val = peek(stack);\n    stack->size--;\n    return val;\n}\n
    array_stack.zig
    // \u57fa\u4e8e\u6570\u7ec4\u5b9e\u73b0\u7684\u6808\nfn ArrayStack(comptime T: type) type {\n    return struct {\n        const Self = @This();\n\n        stack: ?std.ArrayList(T) = null,     \n\n        // \u6784\u9020\u65b9\u6cd5\uff08\u5206\u914d\u5185\u5b58+\u521d\u59cb\u5316\u6808\uff09\n        pub fn init(self: *Self, allocator: std.mem.Allocator) void {\n            if (self.stack == null) {\n                self.stack = std.ArrayList(T).init(allocator);\n            }\n        }\n\n        // \u6790\u6784\u65b9\u6cd5\uff08\u91ca\u653e\u5185\u5b58\uff09\n        pub fn deinit(self: *Self) void {\n            if (self.stack == null) return;\n            self.stack.?.deinit();\n        }\n\n        // \u83b7\u53d6\u6808\u7684\u957f\u5ea6\n        pub fn size(self: *Self) usize {\n            return self.stack.?.items.len;\n        }\n\n        // \u5224\u65ad\u6808\u662f\u5426\u4e3a\u7a7a\n        pub fn isEmpty(self: *Self) bool {\n            return self.size() == 0;\n        }\n\n        // \u8bbf\u95ee\u6808\u9876\u5143\u7d20\n        pub fn peek(self: *Self) T {\n            if (self.isEmpty()) @panic(\"\u6808\u4e3a\u7a7a\");\n            return self.stack.?.items[self.size() - 1];\n        }  \n\n        // \u5165\u6808\n        pub fn push(self: *Self, num: T) !void {\n            try self.stack.?.append(num);\n        } \n\n        // \u51fa\u6808\n        pub fn pop(self: *Self) T {\n            var num = self.stack.?.pop();\n            return num;\n        } \n\n        // \u8fd4\u56de ArrayList\n        pub fn toList(self: *Self) std.ArrayList(T) {\n            return 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\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 None \u3002\u7531\u4e8e\u5c42\u5e8f\u904d\u5386\u5e8f\u5217\u5e76\u4e0d\u5305\u542b\u8fd9\u4e9b None \uff0c\u56e0\u6b64\u6211\u4eec\u65e0\u6cd5\u4ec5\u51ed\u8be5\u5e8f\u5217\u6765\u63a8\u6d4b 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 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\uff0cNone \u53ea\u51fa\u73b0\u5728\u6700\u5e95\u5c42\u4e14\u9760\u53f3\u7684\u4f4d\u7f6e\uff0c\u56e0\u6b64\u6240\u6709 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 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\"\"\"\n\n    def __init__(self, arr: list[int | None]):\n        \"\"\"\u6784\u9020\u65b9\u6cd5\"\"\"\n        self._tree = list(arr)\n\n    def size(self):\n        \"\"\"\u8282\u70b9\u6570\u91cf\"\"\"\n        return len(self._tree)\n\n    def 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\n        if i < 0 or i >= self.size():\n            return None\n        return self._tree[i]\n\n    def left(self, i: int) -> int | None:\n        \"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n        return 2 * i + 1\n\n    def right(self, i: int) -> int | None:\n        \"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n        return 2 * i + 2\n\n    def parent(self, i: int) -> int | None:\n        \"\"\"\u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15\"\"\"\n        return (i - 1) // 2\n\n    def level_order(self) -> list[int]:\n        \"\"\"\u5c42\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        # \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for i in range(self.size()):\n            if self.val(i) is not None:\n                self.res.append(self.val(i))\n        return self.res\n\n    def dfs(self, i: int, order: str):\n        \"\"\"\u6df1\u5ea6\u4f18\u5148\u904d\u5386\"\"\"\n        if self.val(i) is None:\n            return\n        # \u524d\u5e8f\u904d\u5386\n        if order == \"pre\":\n            self.res.append(self.val(i))\n        self.dfs(self.left(i), order)\n        # \u4e2d\u5e8f\u904d\u5386\n        if order == \"in\":\n            self.res.append(self.val(i))\n        self.dfs(self.right(i), order)\n        # \u540e\u5e8f\u904d\u5386\n        if order == \"post\":\n            self.res.append(self.val(i))\n\n    def pre_order(self) -> list[int]:\n        \"\"\"\u524d\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        self.dfs(0, order=\"pre\")\n        return self.res\n\n    def in_order(self) -> list[int]:\n        \"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        self.dfs(0, order=\"in\")\n        return self.res\n\n    def post_order(self) -> list[int]:\n        \"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\n        self.res = []\n        self.dfs(0, order=\"post\")\n        return self.res\n
    array_binary_tree.cpp
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n  public:\n    /* \u6784\u9020\u65b9\u6cd5 */\n    ArrayBinaryTree(vector<int> arr) {\n        tree = arr;\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    int size() {\n        return tree.size();\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    int val(int i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de INT_MAX \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= size())\n            return INT_MAX;\n        return tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    int left(int i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    int right(int i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    int parent(int i) {\n        return (i - 1) / 2;\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    vector<int> levelOrder() {\n        vector<int> res;\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (int i = 0; i < size(); i++) {\n            if (val(i) != INT_MAX)\n                res.push_back(val(i));\n        }\n        return res;\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    vector<int> preOrder() {\n        vector<int> res;\n        dfs(0, \"pre\", res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    vector<int> inOrder() {\n        vector<int> res;\n        dfs(0, \"in\", res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    vector<int> postOrder() {\n        vector<int> res;\n        dfs(0, \"post\", res);\n        return res;\n    }\n\n  private:\n    vector<int> tree;\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    void dfs(int i, string order, vector<int> &res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (val(i) == INT_MAX)\n            return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order == \"pre\")\n            res.push_back(val(i));\n        dfs(left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order == \"in\")\n            res.push_back(val(i));\n        dfs(right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order == \"post\")\n            res.push_back(val(i));\n    }\n};\n
    array_binary_tree.java
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n    private List<Integer> tree;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    public ArrayBinaryTree(List<Integer> arr) {\n        tree = new ArrayList<>(arr);\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    public int size() {\n        return tree.size();\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    public Integer val(int i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= size())\n            return null;\n        return tree.get(i);\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public Integer left(int i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public Integer right(int i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    public Integer parent(int i) {\n        return (i - 1) / 2;\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    public List<Integer> levelOrder() {\n        List<Integer> res = new ArrayList<>();\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (int i = 0; i < size(); i++) {\n            if (val(i) != null)\n                res.add(val(i));\n        }\n        return res;\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    private void dfs(Integer i, String order, List<Integer> res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (val(i) == null)\n            return;\n        // \u524d\u5e8f\u904d\u5386\n        if (\"pre\".equals(order))\n            res.add(val(i));\n        dfs(left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (\"in\".equals(order))\n            res.add(val(i));\n        dfs(right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (\"post\".equals(order))\n            res.add(val(i));\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    public List<Integer> preOrder() {\n        List<Integer> res = new ArrayList<>();\n        dfs(0, \"pre\", res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    public List<Integer> inOrder() {\n        List<Integer> res = new ArrayList<>();\n        dfs(0, \"in\", res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    public List<Integer> postOrder() {\n        List<Integer> res = new ArrayList<>();\n        dfs(0, \"post\", res);\n        return res;\n    }\n}\n
    array_binary_tree.cs
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree(List<int?> arr) {\n    List<int?> tree = new(arr);\n\n    /* \u8282\u70b9\u6570\u91cf */\n    public int Size() {\n        return tree.Count;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    public int? Val(int i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= Size())\n            return null;\n        return tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public int Left(int i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    public int Right(int i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    public int Parent(int i) {\n        return (i - 1) / 2;\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    public List<int> LevelOrder() {\n        List<int> res = [];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (int i = 0; i < Size(); i++) {\n            if (Val(i).HasValue)\n                res.Add(Val(i)!.Value);\n        }\n        return res;\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    void DFS(int i, string order, List<int> res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (!Val(i).HasValue)\n            return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order == \"pre\")\n            res.Add(Val(i)!.Value);\n        DFS(Left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order == \"in\")\n            res.Add(Val(i)!.Value);\n        DFS(Right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order == \"post\")\n            res.Add(Val(i)!.Value);\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    public List<int> PreOrder() {\n        List<int> res = [];\n        DFS(0, \"pre\", res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    public List<int> InOrder() {\n        List<int> res = [];\n        DFS(0, \"in\", res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    public List<int> PostOrder() {\n        List<int> res = [];\n        DFS(0, \"post\", res);\n        return res;\n    }\n}\n
    array_binary_tree.go
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\ntype arrayBinaryTree struct {\n    tree []any\n}\n\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc newArrayBinaryTree(arr []any) *arrayBinaryTree {\n    return &arrayBinaryTree{\n        tree: arr,\n    }\n}\n\n/* \u8282\u70b9\u6570\u91cf */\nfunc (abt *arrayBinaryTree) size() int {\n    return len(abt.tree)\n}\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\n    if i < 0 || i >= abt.size() {\n        return nil\n    }\n    return abt.tree[i]\n}\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 {\n    return 2*i + 1\n}\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 {\n    return 2*i + 2\n}\n\n/* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\nfunc (abt *arrayBinaryTree) parent(i int) int {\n    return (i - 1) / 2\n}\n\n/* \u5c42\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) levelOrder() []any {\n    var res []any\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n    for i := 0; i < abt.size(); i++ {\n        if abt.val(i) != nil {\n            res = append(res, abt.val(i))\n        }\n    }\n    return res\n}\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\n    if abt.val(i) == nil {\n        return\n    }\n    // \u524d\u5e8f\u904d\u5386\n    if order == \"pre\" {\n        *res = append(*res, abt.val(i))\n    }\n    abt.dfs(abt.left(i), order, res)\n    // \u4e2d\u5e8f\u904d\u5386\n    if order == \"in\" {\n        *res = append(*res, abt.val(i))\n    }\n    abt.dfs(abt.right(i), order, res)\n    // \u540e\u5e8f\u904d\u5386\n    if order == \"post\" {\n        *res = append(*res, abt.val(i))\n    }\n}\n\n/* \u524d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) preOrder() []any {\n    var res []any\n    abt.dfs(0, \"pre\", &res)\n    return res\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) inOrder() []any {\n    var res []any\n    abt.dfs(0, \"in\", &res)\n    return res\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunc (abt *arrayBinaryTree) postOrder() []any {\n    var res []any\n    abt.dfs(0, \"post\", &res)\n    return res\n}\n
    array_binary_tree.swift
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n    private var tree: [Int?]\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    init(arr: [Int?]) {\n        tree = arr\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    func size() -> Int {\n        tree.count\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    func val(i: Int) -> Int? {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if i < 0 || i >= size() {\n            return nil\n        }\n        return tree[i]\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    func left(i: Int) -> Int {\n        2 * i + 1\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    func right(i: Int) -> Int {\n        2 * i + 2\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    func parent(i: Int) -> Int {\n        (i - 1) / 2\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    func levelOrder() -> [Int] {\n        var res: [Int] = []\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for i in stride(from: 0, to: size(), by: 1) {\n            if let val = val(i: i) {\n                res.append(val)\n            }\n        }\n        return res\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    private func dfs(i: Int, order: String, res: inout [Int]) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        guard let val = val(i: i) else {\n            return\n        }\n        // \u524d\u5e8f\u904d\u5386\n        if order == \"pre\" {\n            res.append(val)\n        }\n        dfs(i: left(i: i), order: order, res: &res)\n        // \u4e2d\u5e8f\u904d\u5386\n        if order == \"in\" {\n            res.append(val)\n        }\n        dfs(i: right(i: i), order: order, res: &res)\n        // \u540e\u5e8f\u904d\u5386\n        if order == \"post\" {\n            res.append(val)\n        }\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    func preOrder() -> [Int] {\n        var res: [Int] = []\n        dfs(i: 0, order: \"pre\", res: &res)\n        return res\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    func inOrder() -> [Int] {\n        var res: [Int] = []\n        dfs(i: 0, order: \"in\", res: &res)\n        return res\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    func postOrder() -> [Int] {\n        var res: [Int] = []\n        dfs(i: 0, order: \"post\", res: &res)\n        return res\n    }\n}\n
    array_binary_tree.js
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n    #tree;\n\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(arr) {\n        this.#tree = arr;\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    size() {\n        return this.#tree.length;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    val(i) {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= this.size()) return null;\n        return this.#tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    left(i) {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    right(i) {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    parent(i) {\n        return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    levelOrder() {\n        let res = [];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (let i = 0; i < this.size(); i++) {\n            if (this.val(i) !== null) res.push(this.val(i));\n        }\n        return res;\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    #dfs(i, order, res) {\n        // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n        if (this.val(i) === null) return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order === 'pre') res.push(this.val(i));\n        this.#dfs(this.left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order === 'in') res.push(this.val(i));\n        this.#dfs(this.right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order === 'post') res.push(this.val(i));\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    preOrder() {\n        const res = [];\n        this.#dfs(0, 'pre', res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    inOrder() {\n        const res = [];\n        this.#dfs(0, 'in', res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    postOrder() {\n        const res = [];\n        this.#dfs(0, 'post', res);\n        return 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\n    /* \u6784\u9020\u65b9\u6cd5 */\n    constructor(arr: (number | null)[]) {\n        this.#tree = arr;\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    size(): number {\n        return this.#tree.length;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    val(i: number): number | null {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if (i < 0 || i >= this.size()) return null;\n        return this.#tree[i];\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    left(i: number): number {\n        return 2 * i + 1;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    right(i: number): number {\n        return 2 * i + 2;\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    parent(i: number): number {\n        return Math.floor((i - 1) / 2); // \u5411\u4e0b\u6574\u9664\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    levelOrder(): number[] {\n        let res = [];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for (let i = 0; i < this.size(); i++) {\n            if (this.val(i) !== null) res.push(this.val(i));\n        }\n        return res;\n    }\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\n        if (this.val(i) === null) return;\n        // \u524d\u5e8f\u904d\u5386\n        if (order === 'pre') res.push(this.val(i));\n        this.#dfs(this.left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if (order === 'in') res.push(this.val(i));\n        this.#dfs(this.right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if (order === 'post') res.push(this.val(i));\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    preOrder(): (number | null)[] {\n        const res = [];\n        this.#dfs(0, 'pre', res);\n        return res;\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    inOrder(): (number | null)[] {\n        const res = [];\n        this.#dfs(0, 'in', res);\n        return res;\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    postOrder(): (number | null)[] {\n        const res = [];\n        this.#dfs(0, 'post', res);\n        return res;\n    }\n}\n
    array_binary_tree.dart
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nclass ArrayBinaryTree {\n  late List<int?> _tree;\n\n  /* \u6784\u9020\u65b9\u6cd5 */\n  ArrayBinaryTree(this._tree);\n\n  /* \u8282\u70b9\u6570\u91cf */\n  int size() {\n    return _tree.length;\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n  int? val(int i) {\n    // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de null \uff0c\u4ee3\u8868\u7a7a\u4f4d\n    if (i < 0 || i >= size()) {\n      return null;\n    }\n    return _tree[i];\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n  int? left(int i) {\n    return 2 * i + 1;\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n  int? right(int i) {\n    return 2 * i + 2;\n  }\n\n  /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n  int? parent(int i) {\n    return (i - 1) ~/ 2;\n  }\n\n  /* \u5c42\u5e8f\u904d\u5386 */\n  List<int> levelOrder() {\n    List<int> res = [];\n    for (int i = 0; i < size(); i++) {\n      if (val(i) != null) {\n        res.add(val(i)!);\n      }\n    }\n    return res;\n  }\n\n  /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n  void dfs(int i, String order, List<int?> res) {\n    // \u82e5\u4e3a\u7a7a\u4f4d\uff0c\u5219\u8fd4\u56de\n    if (val(i) == null) {\n      return;\n    }\n    // \u524d\u5e8f\u904d\u5386\n    if (order == 'pre') {\n      res.add(val(i));\n    }\n    dfs(left(i)!, order, res);\n    // \u4e2d\u5e8f\u904d\u5386\n    if (order == 'in') {\n      res.add(val(i));\n    }\n    dfs(right(i)!, order, res);\n    // \u540e\u5e8f\u904d\u5386\n    if (order == 'post') {\n      res.add(val(i));\n    }\n  }\n\n  /* \u524d\u5e8f\u904d\u5386 */\n  List<int?> preOrder() {\n    List<int?> res = [];\n    dfs(0, 'pre', res);\n    return res;\n  }\n\n  /* \u4e2d\u5e8f\u904d\u5386 */\n  List<int?> inOrder() {\n    List<int?> res = [];\n    dfs(0, 'in', res);\n    return res;\n  }\n\n  /* \u540e\u5e8f\u904d\u5386 */\n  List<int?> postOrder() {\n    List<int?> res = [];\n    dfs(0, 'post', res);\n    return res;\n  }\n}\n
    array_binary_tree.rs
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7c7b */\nstruct ArrayBinaryTree {\n    tree: Vec<Option<i32>>,\n}\n\nimpl ArrayBinaryTree {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(arr: Vec<Option<i32>>) -> Self {\n        Self { tree: arr }\n    }\n\n    /* \u8282\u70b9\u6570\u91cf */\n    fn size(&self) -> i32 {\n        self.tree.len() as i32\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u503c */\n    fn val(&self, i: i32) -> Option<i32> {\n        // \u82e5\u7d22\u5f15\u8d8a\u754c\uff0c\u5219\u8fd4\u56de None \uff0c\u4ee3\u8868\u7a7a\u4f4d\n        if i < 0 || i >= self.size() {\n            None\n        } else {\n            self.tree[i as usize]\n        }\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u5de6\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    fn left(&self, i: i32) -> i32 {\n        2 * i + 1\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u53f3\u5b50\u8282\u70b9\u7684\u7d22\u5f15 */\n    fn right(&self, i: i32) -> i32 {\n        2 * i + 2\n    }\n\n    /* \u83b7\u53d6\u7d22\u5f15\u4e3a i \u8282\u70b9\u7684\u7236\u8282\u70b9\u7684\u7d22\u5f15 */\n    fn parent(&self, i: i32) -> i32 {\n        (i - 1) / 2\n    }\n\n    /* \u5c42\u5e8f\u904d\u5386 */\n    fn level_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n        for i in 0..self.size() {\n            if let Some(val) = self.val(i) {\n                res.push(val)\n            }\n        }\n        res\n    }\n\n    /* \u6df1\u5ea6\u4f18\u5148\u904d\u5386 */\n    fn dfs(&self, i: i32, order: &str, res: &mut Vec<i32>) {\n        if self.val(i).is_none() {\n            return;\n        }\n        let val = self.val(i).unwrap();\n        // \u524d\u5e8f\u904d\u5386\n        if order == \"pre\" {\n            res.push(val);\n        }\n        self.dfs(self.left(i), order, res);\n        // \u4e2d\u5e8f\u904d\u5386\n        if order == \"in\" {\n            res.push(val);\n        }\n        self.dfs(self.right(i), order, res);\n        // \u540e\u5e8f\u904d\u5386\n        if order == \"post\" {\n            res.push(val);\n        }\n    }\n\n    /* \u524d\u5e8f\u904d\u5386 */\n    fn pre_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        self.dfs(0, \"pre\", &mut res);\n        res\n    }\n\n    /* \u4e2d\u5e8f\u904d\u5386 */\n    fn in_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        self.dfs(0, \"in\", &mut res);\n        res\n    }\n\n    /* \u540e\u5e8f\u904d\u5386 */\n    fn post_order(&self) -> Vec<i32> {\n        let mut res = vec![];\n        self.dfs(0, \"post\", &mut res);\n        res\n    }\n}\n
    array_binary_tree.c
    /* \u6570\u7ec4\u8868\u793a\u4e0b\u7684\u4e8c\u53c9\u6811\u7ed3\u6784\u4f53 */\ntypedef struct {\n    int *tree;\n    int size;\n} ArrayBinaryTree;\n\n/* \u6784\u9020\u51fd\u6570 */\nArrayBinaryTree *newArrayBinaryTree(int *arr, int arrSize) {\n    ArrayBinaryTree *abt = (ArrayBinaryTree *)malloc(sizeof(ArrayBinaryTree));\n    abt->tree = malloc(sizeof(int) * arrSize);\n    memcpy(abt->tree, arr, sizeof(int) * arrSize);\n    abt->size = arrSize;\n    return abt;\n}\n\n/* \u6790\u6784\u51fd\u6570 */\nvoid delArrayBinaryTree(ArrayBinaryTree *abt) {\n    free(abt->tree);\n    free(abt);\n}\n\n/* \u8282\u70b9\u6570\u91cf */\nint size(ArrayBinaryTree *abt) {\n    return abt->size;\n}\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\n    if (i < 0 || i >= size(abt))\n        return INT_MAX;\n    return abt->tree[i];\n}\n\n/* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    // \u76f4\u63a5\u904d\u5386\u6570\u7ec4\n    for (int i = 0; i < size(abt); i++) {\n        if (val(abt, i) != INT_MAX)\n            res[index++] = val(abt, i);\n    }\n    *returnSize = index;\n    return res;\n}\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\n    if (val(abt, i) == INT_MAX)\n        return;\n    // \u524d\u5e8f\u904d\u5386\n    if (strcmp(order, \"pre\") == 0)\n        res[(*index)++] = val(abt, i);\n    dfs(abt, left(i), order, res, index);\n    // \u4e2d\u5e8f\u904d\u5386\n    if (strcmp(order, \"in\") == 0)\n        res[(*index)++] = val(abt, i);\n    dfs(abt, right(i), order, res, index);\n    // \u540e\u5e8f\u904d\u5386\n    if (strcmp(order, \"post\") == 0)\n        res[(*index)++] = val(abt, i);\n}\n\n/* \u524d\u5e8f\u904d\u5386 */\nint *preOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    dfs(abt, 0, \"pre\", res, &index);\n    *returnSize = index;\n    return res;\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nint *inOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    dfs(abt, 0, \"in\", res, &index);\n    *returnSize = index;\n    return res;\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nint *postOrder(ArrayBinaryTree *abt, int *returnSize) {\n    int *res = (int *)malloc(sizeof(int) * size(abt));\n    int index = 0;\n    dfs(abt, 0, \"post\", res, &index);\n    *returnSize = index;\n    return 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 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\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)\\) \u52a3\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\u52a3\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\u201cAn algorithm for the organization of information\u201d\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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val                 # \u8282\u70b9\u503c\n        self.height: int = 0                # \u8282\u70b9\u9ad8\u5ea6\n        self.left: TreeNode | None = None   # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n        self.right: TreeNode | None = None  # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nstruct TreeNode {\n    int val{};          // \u8282\u70b9\u503c\n    int height = 0;     // \u8282\u70b9\u9ad8\u5ea6\n    TreeNode *left{};   // \u5de6\u5b50\u8282\u70b9\n    TreeNode *right{};  // \u53f3\u5b50\u8282\u70b9\n    TreeNode() = default;\n    explicit TreeNode(int x) : val(x){}\n};\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    public int val;        // \u8282\u70b9\u503c\n    public int height;     // \u8282\u70b9\u9ad8\u5ea6\n    public TreeNode left;  // \u5de6\u5b50\u8282\u70b9\n    public TreeNode right; // \u53f3\u5b50\u8282\u70b9\n    public TreeNode(int x) { val = x; }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\n    public int? val = x;    // \u8282\u70b9\u503c\n    public int height;      // \u8282\u70b9\u9ad8\u5ea6\n    public TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    public TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
    /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\n    Val    int       // \u8282\u70b9\u503c\n    Height int       // \u8282\u70b9\u9ad8\u5ea6\n    Left   *TreeNode // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    Right  *TreeNode // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    var val: Int // \u8282\u70b9\u503c\n    var height: Int // \u8282\u70b9\u9ad8\u5ea6\n    var left: TreeNode? // \u5de6\u5b50\u8282\u70b9\n    var right: TreeNode? // \u53f3\u5b50\u8282\u70b9\n\n    init(x: Int) {\n        val = x\n        height = 0\n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val; // \u8282\u70b9\u503c\n    height; //\u8282\u70b9\u9ad8\u5ea6\n    left; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    constructor(val, left, right, height) {\n        this.val = val === undefined ? 0 : val;\n        this.height = height === undefined ? 0 : height;\n        this.left = left === undefined ? null : left;\n        this.right = right === undefined ? null : right;\n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val: number;            // \u8282\u70b9\u503c\n    height: number;         // \u8282\u70b9\u9ad8\u5ea6\n    left: TreeNode | null;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    right: TreeNode | null; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    constructor(val?: number, height?: number, left?: TreeNode | null, right?: TreeNode | null) {\n        this.val = val === undefined ? 0 : val;\n        this.height = height === undefined ? 0 : height; \n        this.left = left === undefined ? null : left; \n        this.right = right === undefined ? null : right; \n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n  int val;         // \u8282\u70b9\u503c\n  int height;      // \u8282\u70b9\u9ad8\u5ea6\n  TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\n  TreeNode? right; // \u53f3\u5b50\u8282\u70b9\n  TreeNode(this.val, [this.height = 0, this.left, this.right]);\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\n    val: i32,                               // \u8282\u70b9\u503c\n    height: i32,                            // \u8282\u70b9\u9ad8\u5ea6\n    left: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\n    right: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\n}\n\nimpl TreeNode {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(val: i32) -> Rc<RefCell<Self>> {\n        Rc::new(RefCell::new(Self {\n            val,\n            height: 0,\n            left: None,\n            right: None\n        }))\n    }\n}\n
    /* AVL \u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nTreeNode struct TreeNode {\n    int val;\n    int height;\n    struct TreeNode *left;\n    struct TreeNode *right;\n} TreeNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\n    TreeNode *node;\n\n    node = (TreeNode *)malloc(sizeof(TreeNode));\n    node->val = val;\n    node->height = 0;\n    node->left = NULL;\n    node->right = NULL;\n    return node;\n}\n
    \n

    \u201c\u8282\u70b9\u9ad8\u5ea6\u201d\u662f\u6307\u4ece\u8be5\u8282\u70b9\u5230\u5b83\u7684\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\n    if node is not None:\n        return node.height\n    return -1\n\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\n    node.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\n    return node == nullptr ? -1 : node->height;\n}\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\n    node->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\n    return node == null ? -1 : node.height;\n}\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\n    node.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\n    return node == null ? -1 : node.height;\n}\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\n    node.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\n    if node != nil {\n        return node.Height\n    }\n    return -1\n}\n\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfunc (t *aVLTree) updateHeight(node *TreeNode) {\n    lh := t.height(node.Left)\n    rh := t.height(node.Right)\n    // \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\n    if lh > rh {\n        node.Height = lh + 1\n    } else {\n        node.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\n    node == nil ? -1 : node!.height\n}\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\n    node?.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\n    return node === null ? -1 : node.height;\n}\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\n    node.height =\n        Math.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\n    return node === null ? -1 : node.height;\n}\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\n    node.height =\n        Math.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\n  return node == null ? -1 : node.height;\n}\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\n  node!.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\n    match node {\n        Some(node) => node.borrow().height,\n        None => -1,\n    }\n}\n\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nfn update_height(node: OptionTreeNodeRc) {\n    if let Some(node) = node {\n        let left = node.borrow().left.clone();\n        let right = node.borrow().right.clone();\n        // \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\n        node.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\n    if (node != NULL) {\n        return node->height;\n    }\n    return -1;\n}\n\n/* \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6 */\nvoid updateHeight(TreeNode *node) {\n    int lh = height(node->left);\n    int rh = height(node->right);\n    // \u8282\u70b9\u9ad8\u5ea6\u7b49\u4e8e\u6700\u9ad8\u5b50\u6811\u9ad8\u5ea6 + 1\n    if (lh > rh) {\n        node->height = lh + 1;\n    } else {\n        node->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\n    return if (node == null) -1 else node.?.height;\n}\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\n    node.?.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\n    if node is None:\n        return 0\n    # \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == nullptr)\n        return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == null)\n        return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if node == nil {\n        return 0\n    }\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    guard let node = node else { return 0 }\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node === null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node === null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n  if (node == null) return 0;\n  // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n  return height(node.left) - height(node.right);\n}\n
    avl_tree.rs
    /* \u83b7\u53d6\u5e73\u8861\u56e0\u5b50 */\nfn balance_factor(node: OptionTreeNodeRc) -> i32 {\n    match node {\n        // \u7a7a\u8282\u70b9\u5e73\u8861\u56e0\u5b50\u4e3a 0\n        None => 0,\n        // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n        Some(node) => {\n            Self::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\n    if (node == NULL) {\n        return 0;\n    }\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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\n    if (node == null) return 0;\n    // \u8282\u70b9\u5e73\u8861\u56e0\u5b50 = \u5de6\u5b50\u6811\u9ad8\u5ea6 - \u53f3\u5b50\u6811\u9ad8\u5ea6\n    return 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 grand_child \uff09\u65f6\uff0c\u9700\u8981\u5728\u53f3\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grand_child \u4f5c\u4e3a node \u7684\u5de6\u5b50\u8282\u70b9\u3002

    \u56fe 7-27 \u00a0 \u6709 grand_child \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\"\"\"\n    child = node.left\n    grand_child = child.right\n    # \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node\n    node.left = grand_child\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    self.update_height(child)\n    # \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n
    avl_tree.cpp
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\n    TreeNode *child = node->left;\n    TreeNode *grandChild = child->right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child->right = node;\n    node->left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.java
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode rightRotate(TreeNode node) {\n    TreeNode child = node.left;\n    TreeNode grandChild = child.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.cs
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? RightRotate(TreeNode? node) {\n    TreeNode? child = node?.left;\n    TreeNode? grandChild = child?.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    UpdateHeight(node);\n    UpdateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.go
    /* \u53f3\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) rightRotate(node *TreeNode) *TreeNode {\n    child := node.Left\n    grandChild := child.Right\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.Right = node\n    node.Left = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    t.updateHeight(child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.swift
    /* \u53f3\u65cb\u64cd\u4f5c */\nfunc rightRotate(node: TreeNode?) -> TreeNode? {\n    let child = node?.left\n    let grandChild = child?.right\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child?.right = node\n    node?.left = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node: node)\n    updateHeight(node: child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.js
    /* \u53f3\u65cb\u64cd\u4f5c */\n#rightRotate(node) {\n    const child = node.left;\n    const grandChild = child.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.#updateHeight(node);\n    this.#updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.ts
    /* \u53f3\u65cb\u64cd\u4f5c */\nrightRotate(node: TreeNode): TreeNode {\n    const child = node.left;\n    const grandChild = child.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.right = node;\n    node.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.updateHeight(node);\n    this.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.dart
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode? rightRotate(TreeNode? node) {\n  TreeNode? child = node!.left;\n  TreeNode? grandChild = child!.right;\n  // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n  child.right = node;\n  node.left = grandChild;\n  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n  updateHeight(node);\n  updateHeight(child);\n  // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return child;\n}\n
    avl_tree.rs
    /* \u53f3\u65cb\u64cd\u4f5c */\nfn right_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\n    match node {\n        Some(node) => {\n            let child = node.borrow().left.clone().unwrap();\n            let grand_child = child.borrow().right.clone();\n            // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n            child.borrow_mut().right = Some(node.clone());\n            node.borrow_mut().left = grand_child;\n            // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n            Self::update_height(Some(node));\n            Self::update_height(Some(child.clone()));\n            // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(child)\n        }\n        None => None,\n    }\n}\n
    avl_tree.c
    /* \u53f3\u65cb\u64cd\u4f5c */\nTreeNode *rightRotate(TreeNode *node) {\n    TreeNode *child, *grandChild;\n    child = node->left;\n    grandChild = child->right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child->right = node;\n    node->left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.zig
    // \u53f3\u65cb\u64cd\u4f5c\nfn rightRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\n    var child = node.?.left;\n    var grandChild = child.?.right;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u53f3\u65cb\u8f6c\n    child.?.right = node;\n    node.?.left = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.updateHeight(node);\n    self.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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 grand_child \uff09\u65f6\uff0c\u9700\u8981\u5728\u5de6\u65cb\u4e2d\u6dfb\u52a0\u4e00\u6b65\uff1a\u5c06 grand_child \u4f5c\u4e3a node \u7684\u53f3\u5b50\u8282\u70b9\u3002

    \u56fe 7-29 \u00a0 \u6709 grand_child \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\"\"\"\n    child = node.right\n    grand_child = child.left\n    # \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node\n    node.right = grand_child\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    self.update_height(child)\n    # \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n
    avl_tree.cpp
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\n    TreeNode *child = node->right;\n    TreeNode *grandChild = child->left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child->left = node;\n    node->right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.java
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode leftRotate(TreeNode node) {\n    TreeNode child = node.right;\n    TreeNode grandChild = child.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.cs
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? LeftRotate(TreeNode? node) {\n    TreeNode? child = node?.right;\n    TreeNode? grandChild = child?.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    UpdateHeight(node);\n    UpdateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.go
    /* \u5de6\u65cb\u64cd\u4f5c */\nfunc (t *aVLTree) leftRotate(node *TreeNode) *TreeNode {\n    child := node.Right\n    grandChild := child.Left\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.Left = node\n    node.Right = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    t.updateHeight(child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.swift
    /* \u5de6\u65cb\u64cd\u4f5c */\nfunc leftRotate(node: TreeNode?) -> TreeNode? {\n    let child = node?.right\n    let grandChild = child?.left\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child?.left = node\n    node?.right = grandChild\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node: node)\n    updateHeight(node: child)\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child\n}\n
    avl_tree.js
    /* \u5de6\u65cb\u64cd\u4f5c */\n#leftRotate(node) {\n    const child = node.right;\n    const grandChild = child.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.#updateHeight(node);\n    this.#updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.ts
    /* \u5de6\u65cb\u64cd\u4f5c */\nleftRotate(node: TreeNode): TreeNode {\n    const child = node.right;\n    const grandChild = child.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.left = node;\n    node.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    this.updateHeight(node);\n    this.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.dart
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode? leftRotate(TreeNode? node) {\n  TreeNode? child = node!.right;\n  TreeNode? grandChild = child!.left;\n  // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n  child.left = node;\n  node.right = grandChild;\n  // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n  updateHeight(node);\n  updateHeight(child);\n  // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return child;\n}\n
    avl_tree.rs
    /* \u5de6\u65cb\u64cd\u4f5c */\nfn left_rotate(node: OptionTreeNodeRc) -> OptionTreeNodeRc {\n    match node {\n        Some(node) => {\n            let child = node.borrow().right.clone().unwrap();\n            let grand_child = child.borrow().left.clone();\n            // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n            child.borrow_mut().left = Some(node.clone());\n            node.borrow_mut().right = grand_child;\n            // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n            Self::update_height(Some(node));\n            Self::update_height(Some(child.clone()));\n            // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(child)\n        }\n        None => None,\n    }\n}\n
    avl_tree.c
    /* \u5de6\u65cb\u64cd\u4f5c */\nTreeNode *leftRotate(TreeNode *node) {\n    TreeNode *child, *grandChild;\n    child = node->right;\n    grandChild = child->left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child->left = node;\n    node->right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return child;\n}\n
    avl_tree.zig
    // \u5de6\u65cb\u64cd\u4f5c\nfn leftRotate(self: *Self, node: ?*inc.TreeNode(T)) ?*inc.TreeNode(T) {\n    var child = node.?.right;\n    var grandChild = child.?.left;\n    // \u4ee5 child \u4e3a\u539f\u70b9\uff0c\u5c06 node \u5411\u5de6\u65cb\u8f6c\n    child.?.left = node;\n    node.?.right = grandChild;\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.updateHeight(node);\n    self.updateHeight(child);\n    // \u8fd4\u56de\u65cb\u8f6c\u540e\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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\n    balance_factor = self.balance_factor(node)\n    # \u5de6\u504f\u6811\n    if balance_factor > 1:\n        if self.balance_factor(node.left) >= 0:\n            # \u53f3\u65cb\n            return self.right_rotate(node)\n        else:\n            # \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = self.left_rotate(node.left)\n            return self.right_rotate(node)\n    # \u53f3\u504f\u6811\n    elif balance_factor < -1:\n        if self.balance_factor(node.right) <= 0:\n            # \u5de6\u65cb\n            return self.left_rotate(node)\n        else:\n            # \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = self.right_rotate(node.right)\n            return self.left_rotate(node)\n    # \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    int _balanceFactor = balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (_balanceFactor > 1) {\n        if (balanceFactor(node->left) >= 0) {\n            // \u53f3\u65cb\n            return rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node->left = leftRotate(node->left);\n            return rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (_balanceFactor < -1) {\n        if (balanceFactor(node->right) <= 0) {\n            // \u5de6\u65cb\n            return leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node->right = rightRotate(node->right);\n            return leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    int balanceFactor = balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactor > 1) {\n        if (balanceFactor(node.left) >= 0) {\n            // \u53f3\u65cb\n            return rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = leftRotate(node.left);\n            return rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactor < -1) {\n        if (balanceFactor(node.right) <= 0) {\n            // \u5de6\u65cb\n            return leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = rightRotate(node.right);\n            return leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    int balanceFactorInt = BalanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactorInt > 1) {\n        if (BalanceFactor(node?.left) >= 0) {\n            // \u53f3\u65cb\n            return RightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node!.left = LeftRotate(node!.left);\n            return RightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactorInt < -1) {\n        if (BalanceFactor(node?.right) <= 0) {\n            // \u5de6\u65cb\n            return LeftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node!.right = RightRotate(node!.right);\n            return LeftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    bf := t.balanceFactor(node)\n    // \u5de6\u504f\u6811\n    if bf > 1 {\n        if t.balanceFactor(node.Left) >= 0 {\n            // \u53f3\u65cb\n            return t.rightRotate(node)\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.Left = t.leftRotate(node.Left)\n            return t.rightRotate(node)\n        }\n    }\n    // \u53f3\u504f\u6811\n    if bf < -1 {\n        if t.balanceFactor(node.Right) <= 0 {\n            // \u5de6\u65cb\n            return t.leftRotate(node)\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.Right = t.rightRotate(node.Right)\n            return t.leftRotate(node)\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    let balanceFactor = balanceFactor(node: node)\n    // \u5de6\u504f\u6811\n    if balanceFactor > 1 {\n        if self.balanceFactor(node: node?.left) >= 0 {\n            // \u53f3\u65cb\n            return rightRotate(node: node)\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node?.left = leftRotate(node: node?.left)\n            return rightRotate(node: node)\n        }\n    }\n    // \u53f3\u504f\u6811\n    if balanceFactor < -1 {\n        if self.balanceFactor(node: node?.right) <= 0 {\n            // \u5de6\u65cb\n            return leftRotate(node: node)\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node?.right = rightRotate(node: node?.right)\n            return leftRotate(node: node)\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    const balanceFactor = this.balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactor > 1) {\n        if (this.balanceFactor(node.left) >= 0) {\n            // \u53f3\u65cb\n            return this.#rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = this.#leftRotate(node.left);\n            return this.#rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactor < -1) {\n        if (this.balanceFactor(node.right) <= 0) {\n            // \u5de6\u65cb\n            return this.#leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = this.#rightRotate(node.right);\n            return this.#leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    const balanceFactor = this.balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balanceFactor > 1) {\n        if (this.balanceFactor(node.left) >= 0) {\n            // \u53f3\u65cb\n            return this.rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.left = this.leftRotate(node.left);\n            return this.rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balanceFactor < -1) {\n        if (this.balanceFactor(node.right) <= 0) {\n            // \u5de6\u65cb\n            return this.leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.right = this.rightRotate(node.right);\n            return this.leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n  int factor = balanceFactor(node);\n  // \u5de6\u504f\u6811\n  if (factor > 1) {\n    if (balanceFactor(node!.left) >= 0) {\n      // \u53f3\u65cb\n      return rightRotate(node);\n    } else {\n      // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n      node.left = leftRotate(node.left);\n      return rightRotate(node);\n    }\n  }\n  // \u53f3\u504f\u6811\n  if (factor < -1) {\n    if (balanceFactor(node!.right) <= 0) {\n      // \u5de6\u65cb\n      return leftRotate(node);\n    } else {\n      // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n      node.right = rightRotate(node.right);\n      return leftRotate(node);\n    }\n  }\n  // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n  return 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\n    let balance_factor = Self::balance_factor(node.clone());\n    // \u5de6\u504f\u6811\n    if balance_factor > 1 {\n        let node = node.unwrap();\n        if Self::balance_factor(node.borrow().left.clone()) >= 0 {\n            // \u53f3\u65cb\n            Self::right_rotate(Some(node))\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            let left = node.borrow().left.clone();\n            node.borrow_mut().left = Self::left_rotate(left);\n            Self::right_rotate(Some(node))\n        }\n    }\n    // \u53f3\u504f\u6811\n    else if balance_factor < -1 {\n        let node = node.unwrap();\n        if Self::balance_factor(node.borrow().right.clone()) <= 0 {\n            // \u5de6\u65cb\n            Self::left_rotate(Some(node))\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            let right = node.borrow().right.clone();\n            node.borrow_mut().right = Self::right_rotate(right);\n            Self::left_rotate(Some(node))\n        }\n    } else {\n        // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n        node\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\n    int bf = balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (bf > 1) {\n        if (balanceFactor(node->left) >= 0) {\n            // \u53f3\u65cb\n            return rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node->left = leftRotate(node->left);\n            return rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (bf < -1) {\n        if (balanceFactor(node->right) <= 0) {\n            // \u5de6\u65cb\n            return leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node->right = rightRotate(node->right);\n            return leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\n    var balance_factor = self.balanceFactor(node);\n    // \u5de6\u504f\u6811\n    if (balance_factor > 1) {\n        if (self.balanceFactor(node.?.left) >= 0) {\n            // \u53f3\u65cb\n            return self.rightRotate(node);\n        } else {\n            // \u5148\u5de6\u65cb\u540e\u53f3\u65cb\n            node.?.left = self.leftRotate(node.?.left);\n            return self.rightRotate(node);\n        }\n    }\n    // \u53f3\u504f\u6811\n    if (balance_factor < -1) {\n        if (self.balanceFactor(node.?.right) <= 0) {\n            // \u5de6\u65cb\n            return self.leftRotate(node);\n        } else {\n            // \u5148\u53f3\u65cb\u540e\u5de6\u65cb\n            node.?.right = self.rightRotate(node.?.right);\n            return self.leftRotate(node);\n        }\n    }\n    // \u5e73\u8861\u6811\uff0c\u65e0\u987b\u65cb\u8f6c\uff0c\u76f4\u63a5\u8fd4\u56de\n    return 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\"\"\"\n    self._root = self.insert_helper(self._root, val)\n\ndef insert_helper(self, node: TreeNode | None, val: int) -> TreeNode:\n    \"\"\"\u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\n    if node is None:\n        return TreeNode(val)\n    # 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9\n    if val < node.val:\n        node.left = self.insert_helper(node.left, val)\n    elif val > node.val:\n        node.right = self.insert_helper(node.right, val)\n    else:\n        # \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n        return node\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    # 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\n    return self.rotate(node)\n
    avl_tree.cpp
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\n    root = insertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\n    if (node == nullptr)\n        return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node->val)\n        node->left = insertHelper(node->left, val);\n    else if (val > node->val)\n        node->right = insertHelper(node->right, val);\n    else\n        return node;    // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.java
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\n    root = insertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode insertHelper(TreeNode node, int val) {\n    if (node == null)\n        return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val)\n        node.left = insertHelper(node.left, val);\n    else if (val > node.val)\n        node.right = insertHelper(node.right, val);\n    else\n        return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.cs
    /* \u63d2\u5165\u8282\u70b9 */\nvoid Insert(int val) {\n    root = InsertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? InsertHelper(TreeNode? node, int val) {\n    if (node == null) return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val)\n        node.left = InsertHelper(node.left, val);\n    else if (val > node.val)\n        node.right = InsertHelper(node.right, val);\n    else\n        return node;     // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    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 */\n    node = Rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.go
    /* \u63d2\u5165\u8282\u70b9 */\nfunc (t *aVLTree) insert(val int) {\n    t.root = t.insertHelper(t.root, val)\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) insertHelper(node *TreeNode, val int) *TreeNode {\n    if node == nil {\n        return NewTreeNode(val)\n    }\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if val < node.Val.(int) {\n        node.Left = t.insertHelper(node.Left, val)\n    } else if val > node.Val.(int) {\n        node.Right = t.insertHelper(node.Right, val)\n    } else {\n        // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n        return node\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = t.rotate(node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.swift
    /* \u63d2\u5165\u8282\u70b9 */\nfunc insert(val: Int) {\n    root = insertHelper(node: root, val: val)\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc insertHelper(node: TreeNode?, val: Int) -> TreeNode? {\n    var node = node\n    if node == nil {\n        return TreeNode(x: val)\n    }\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if val < node!.val {\n        node?.left = insertHelper(node: node?.left, val: val)\n    } else if val > node!.val {\n        node?.right = insertHelper(node: node?.right, val: val)\n    } else {\n        return node // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    }\n    updateHeight(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 */\n    node = rotate(node: node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.js
    /* \u63d2\u5165\u8282\u70b9 */\ninsert(val) {\n    this.root = this.#insertHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#insertHelper(node, val) {\n    if (node === null) return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val) node.left = this.#insertHelper(node.left, val);\n    else if (val > node.val)\n        node.right = this.#insertHelper(node.right, val);\n    else return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    this.#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 */\n    node = this.#rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.ts
    /* \u63d2\u5165\u8282\u70b9 */\ninsert(val: number): void {\n    this.root = this.insertHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\ninsertHelper(node: TreeNode, val: number): TreeNode {\n    if (node === null) return new TreeNode(val);\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node.val) {\n        node.left = this.insertHelper(node.left, val);\n    } else if (val > node.val) {\n        node.right = this.insertHelper(node.right, val);\n    } else {\n        return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    }\n    this.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 */\n    node = this.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.dart
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(int val) {\n  root = insertHelper(root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? insertHelper(TreeNode? node, int val) {\n  if (node == null) return TreeNode(val);\n  /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n  if (val < node.val)\n    node.left = insertHelper(node.left, val);\n  else if (val > node.val)\n    node.right = insertHelper(node.right, val);\n  else\n    return node; // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n  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 */\n  node = rotate(node);\n  // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return node;\n}\n
    avl_tree.rs
    /* \u63d2\u5165\u8282\u70b9 */\nfn insert(&mut self, val: i32) {\n    self.root = Self::insert_helper(self.root.clone(), val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn insert_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\n    match node {\n        Some(mut node) => {\n            /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n            match {\n                let node_val = node.borrow().val;\n                node_val\n            }\n            .cmp(&val)\n            {\n                Ordering::Greater => {\n                    let left = node.borrow().left.clone();\n                    node.borrow_mut().left = Self::insert_helper(left, val);\n                }\n                Ordering::Less => {\n                    let right = node.borrow().right.clone();\n                    node.borrow_mut().right = Self::insert_helper(right, val);\n                }\n                Ordering::Equal => {\n                    return Some(node); // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n                }\n            }\n            Self::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 */\n            node = Self::rotate(Some(node)).unwrap();\n            // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(node)\n        }\n        None => Some(TreeNode::new(val)),\n    }\n}\n
    avl_tree.c
    /* \u63d2\u5165\u8282\u70b9 */\nvoid insert(AVLTree *tree, int val) {\n    tree->root = insertHelper(tree->root, val);\n}\n\n/* \u9012\u5f52\u63d2\u5165\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *insertHelper(TreeNode *node, int val) {\n    if (node == NULL) {\n        return newTreeNode(val);\n    }\n    /* 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9 */\n    if (val < node->val) {\n        node->left = insertHelper(node->left, val);\n    } else if (val > node->val) {\n        node->right = insertHelper(node->right, val);\n    } else {\n        // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n        return node;\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.zig
    // \u63d2\u5165\u8282\u70b9\nfn insert(self: *Self, val: T) !void {\n    self.root = (try self.insertHelper(self.root, val)).?;\n}\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) {\n    var node = node_;\n    if (node == null) {\n        var tmp_node = try self.mem_allocator.create(inc.TreeNode(T));\n        tmp_node.init(val);\n        return tmp_node;\n    }\n    // 1. \u67e5\u627e\u63d2\u5165\u4f4d\u7f6e\u5e76\u63d2\u5165\u8282\u70b9\n    if (val < node.?.val) {\n        node.?.left = try self.insertHelper(node.?.left, val);\n    } else if (val > node.?.val) {\n        node.?.right = try self.insertHelper(node.?.right, val);\n    } else {\n        return node;            // \u91cd\u590d\u8282\u70b9\u4e0d\u63d2\u5165\uff0c\u76f4\u63a5\u8fd4\u56de\n    }\n    self.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\n    node = self.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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\"\"\"\n    self._root = self.remove_helper(self._root, val)\n\ndef remove_helper(self, node: TreeNode | None, val: int) -> TreeNode | None:\n    \"\"\"\u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09\"\"\"\n    if node is None:\n        return None\n    # 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664\n    if val < node.val:\n        node.left = self.remove_helper(node.left, val)\n    elif val > node.val:\n        node.right = self.remove_helper(node.right, val)\n    else:\n        if node.left is None or node.right is None:\n            child = node.left or node.right\n            # \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if child is None:\n                return None\n            # \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else:\n                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\n            temp = node.right\n            while temp.left is not None:\n                temp = temp.left\n            node.right = self.remove_helper(node.right, temp.val)\n            node.val = temp.val\n    # \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    self.update_height(node)\n    # 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861\n    return self.rotate(node)\n
    avl_tree.cpp
    /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\n    root = removeHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\n    if (node == nullptr)\n        return nullptr;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node->val)\n        node->left = removeHelper(node->left, val);\n    else if (val > node->val)\n        node->right = removeHelper(node->right, val);\n    else {\n        if (node->left == nullptr || node->right == nullptr) {\n            TreeNode *child = node->left != nullptr ? node->left : node->right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == nullptr) {\n                delete node;\n                return nullptr;\n            }\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else {\n                delete node;\n                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\n            TreeNode *temp = node->right;\n            while (temp->left != nullptr) {\n                temp = temp->left;\n            }\n            int tempVal = temp->val;\n            node->right = removeHelper(node->right, temp->val);\n            node->val = tempVal;\n        }\n    }\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.java
    /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\n    root = removeHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode removeHelper(TreeNode node, int val) {\n    if (node == null)\n        return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val)\n        node.left = removeHelper(node.left, val);\n    else if (val > node.val)\n        node.right = removeHelper(node.right, val);\n    else {\n        if (node.left == null || node.right == null) {\n            TreeNode child = node.left != null ? node.left : node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == null)\n                return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else\n                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\n            TreeNode temp = node.right;\n            while (temp.left != null) {\n                temp = temp.left;\n            }\n            node.right = removeHelper(node.right, temp.val);\n            node.val = temp.val;\n        }\n    }\n    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 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.cs
    /* \u5220\u9664\u8282\u70b9 */\nvoid Remove(int val) {\n    root = RemoveHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? RemoveHelper(TreeNode? node, int val) {\n    if (node == null) return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val)\n        node.left = RemoveHelper(node.left, val);\n    else if (val > node.val)\n        node.right = RemoveHelper(node.right, val);\n    else {\n        if (node.left == null || node.right == null) {\n            TreeNode? child = node.left ?? node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == null)\n                return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else\n                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\n            TreeNode? temp = node.right;\n            while (temp.left != null) {\n                temp = temp.left;\n            }\n            node.right = RemoveHelper(node.right, temp.val!.Value);\n            node.val = temp.val;\n        }\n    }\n    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 */\n    node = Rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.go
    /* \u5220\u9664\u8282\u70b9 */\nfunc (t *aVLTree) remove(val int) {\n    t.root = t.removeHelper(t.root, val)\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nfunc (t *aVLTree) removeHelper(node *TreeNode, val int) *TreeNode {\n    if node == nil {\n        return nil\n    }\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if val < node.Val.(int) {\n        node.Left = t.removeHelper(node.Left, val)\n    } else if val > node.Val.(int) {\n        node.Right = t.removeHelper(node.Right, val)\n    } else {\n        if node.Left == nil || node.Right == nil {\n            child := node.Left\n            if node.Right != nil {\n                child = node.Right\n            }\n            if child == nil {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n                return nil\n            } else {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                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\n            temp := node.Right\n            for temp.Left != nil {\n                temp = temp.Left\n            }\n            node.Right = t.removeHelper(node.Right, temp.Val.(int))\n            node.Val = temp.Val\n        }\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    t.updateHeight(node)\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = t.rotate(node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.swift
    /* \u5220\u9664\u8282\u70b9 */\nfunc remove(val: Int) {\n    root = removeHelper(node: root, val: val)\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfunc removeHelper(node: TreeNode?, val: Int) -> TreeNode? {\n    var node = node\n    if node == nil {\n        return nil\n    }\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if val < node!.val {\n        node?.left = removeHelper(node: node?.left, val: val)\n    } else if val > node!.val {\n        node?.right = removeHelper(node: node?.right, val: val)\n    } else {\n        if node?.left == nil || node?.right == nil {\n            let child = node?.left != nil ? node?.left : node?.right\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if child == nil {\n                return nil\n            }\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else {\n                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\n            var temp = node?.right\n            while temp?.left != nil {\n                temp = temp?.left\n            }\n            node?.right = removeHelper(node: node?.right, val: temp!.val)\n            node?.val = temp!.val\n        }\n    }\n    updateHeight(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 */\n    node = rotate(node: node)\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node\n}\n
    avl_tree.js
    /* \u5220\u9664\u8282\u70b9 */\nremove(val) {\n    this.root = this.#removeHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\n#removeHelper(node, val) {\n    if (node === null) return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val) node.left = this.#removeHelper(node.left, val);\n    else if (val > node.val)\n        node.right = this.#removeHelper(node.right, val);\n    else {\n        if (node.left === null || node.right === null) {\n            const child = node.left !== null ? node.left : node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child === null) return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            else 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\n            let temp = node.right;\n            while (temp.left !== null) {\n                temp = temp.left;\n            }\n            node.right = this.#removeHelper(node.right, temp.val);\n            node.val = temp.val;\n        }\n    }\n    this.#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 */\n    node = this.#rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.ts
    /* \u5220\u9664\u8282\u70b9 */\nremove(val: number): void {\n    this.root = this.removeHelper(this.root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nremoveHelper(node: TreeNode, val: number): TreeNode {\n    if (node === null) return null;\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node.val) {\n        node.left = this.removeHelper(node.left, val);\n    } else if (val > node.val) {\n        node.right = this.removeHelper(node.right, val);\n    } else {\n        if (node.left === null || node.right === null) {\n            const child = node.left !== null ? node.left : node.right;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child === null) {\n                return null;\n            } else {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                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\n            let temp = node.right;\n            while (temp.left !== null) {\n                temp = temp.left;\n            }\n            node.right = this.removeHelper(node.right, temp.val);\n            node.val = temp.val;\n        }\n    }\n    this.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 */\n    node = this.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.dart
    /* \u5220\u9664\u8282\u70b9 */\nvoid remove(int val) {\n  root = removeHelper(root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nTreeNode? removeHelper(TreeNode? node, int val) {\n  if (node == null) return null;\n  /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n  if (val < node.val)\n    node.left = removeHelper(node.left, val);\n  else if (val > node.val)\n    node.right = removeHelper(node.right, val);\n  else {\n    if (node.left == null || node.right == null) {\n      TreeNode? child = node.left ?? node.right;\n      // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n      if (child == null)\n        return null;\n      // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n      else\n        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\n      TreeNode? temp = node.right;\n      while (temp!.left != null) {\n        temp = temp.left;\n      }\n      node.right = removeHelper(node.right, temp.val);\n      node.val = temp.val;\n    }\n  }\n  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 */\n  node = rotate(node);\n  // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n  return node;\n}\n
    avl_tree.rs
    /* \u5220\u9664\u8282\u70b9 */\nfn remove(&self, val: i32) {\n    Self::remove_helper(self.root.clone(), val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u65b9\u6cd5\uff09 */\nfn remove_helper(node: OptionTreeNodeRc, val: i32) -> OptionTreeNodeRc {\n    match node {\n        Some(mut node) => {\n            /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n            if val < node.borrow().val {\n                let left = node.borrow().left.clone();\n                node.borrow_mut().left = Self::remove_helper(left, val);\n            } else if val > node.borrow().val {\n                let right = node.borrow().right.clone();\n                node.borrow_mut().right = Self::remove_helper(right, val);\n            } else if node.borrow().left.is_none() || node.borrow().right.is_none() {\n                let child = if node.borrow().left.is_some() {\n                    node.borrow().left.clone()\n                } else {\n                    node.borrow().right.clone()\n                };\n                match child {\n                    // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n                    None => {\n                        return None;\n                    }\n                    // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                    Some(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\n                let mut temp = node.borrow().right.clone().unwrap();\n                loop {\n                    let temp_left = temp.borrow().left.clone();\n                    if temp_left.is_none() {\n                        break;\n                    }\n                    temp = temp_left.unwrap();\n                }\n                let right = node.borrow().right.clone();\n                node.borrow_mut().right = Self::remove_helper(right, temp.borrow().val);\n                node.borrow_mut().val = temp.borrow().val;\n            }\n            Self::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 */\n            node = Self::rotate(Some(node)).unwrap();\n            // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n            Some(node)\n        }\n        None => 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) {\n    TreeNode *root = removeHelper(tree->root, val);\n}\n\n/* \u9012\u5f52\u5220\u9664\u8282\u70b9\uff08\u8f85\u52a9\u51fd\u6570\uff09 */\nTreeNode *removeHelper(TreeNode *node, int val) {\n    TreeNode *child, *grandChild;\n    if (node == NULL) {\n        return NULL;\n    }\n    /* 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664 */\n    if (val < node->val) {\n        node->left = removeHelper(node->left, val);\n    } else if (val > node->val) {\n        node->right = removeHelper(node->right, val);\n    } else {\n        if (node->left == NULL || node->right == NULL) {\n            child = node->left;\n            if (node->right != NULL) {\n                child = node->right;\n            }\n            // \u5b50\u8282\u70b9\u6570\u91cf = 0 \uff0c\u76f4\u63a5\u5220\u9664 node \u5e76\u8fd4\u56de\n            if (child == NULL) {\n                return NULL;\n            } else {\n                // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n                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\n            TreeNode *temp = node->right;\n            while (temp->left != NULL) {\n                temp = temp->left;\n            }\n            int tempVal = temp->val;\n            node->right = removeHelper(node->right, temp->val);\n            node->val = tempVal;\n        }\n    }\n    // \u66f4\u65b0\u8282\u70b9\u9ad8\u5ea6\n    updateHeight(node);\n    /* 2. \u6267\u884c\u65cb\u8f6c\u64cd\u4f5c\uff0c\u4f7f\u8be5\u5b50\u6811\u91cd\u65b0\u6062\u590d\u5e73\u8861 */\n    node = rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return node;\n}\n
    avl_tree.zig
    // \u5220\u9664\u8282\u70b9\nfn remove(self: *Self, val: T) void {\n   self.root = self.removeHelper(self.root, val).?;\n}\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) {\n    var node = node_;\n    if (node == null) return null;\n    // 1. \u67e5\u627e\u8282\u70b9\u5e76\u5220\u9664\n    if (val < node.?.val) {\n        node.?.left = self.removeHelper(node.?.left, val);\n    } else if (val > node.?.val) {\n        node.?.right = self.removeHelper(node.?.right, val);\n    } else {\n        if (node.?.left == null or node.?.right == null) {\n            var 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\n            if (child == null) {\n                return null;\n            // \u5b50\u8282\u70b9\u6570\u91cf = 1 \uff0c\u76f4\u63a5\u5220\u9664 node\n            } else {\n                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\n            var temp = node.?.right;\n            while (temp.?.left != null) {\n                temp = temp.?.left;\n            }\n            node.?.right = self.removeHelper(node.?.right, temp.?.val);\n            node.?.val = temp.?.val;\n        }\n    }\n    self.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\n    node = self.rotate(node);\n    // \u8fd4\u56de\u5b50\u6811\u7684\u6839\u8282\u70b9\n    return 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\"\"\"\n    cur = self._root\n    # \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur is not None:\n        # \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur.val < num:\n            cur = cur.right\n        # \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        elif cur.val > num:\n            cur = cur.left\n        # \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else:\n            break\n    return cur\n
    binary_search_tree.cpp
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(int num) {\n    TreeNode *cur = root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != nullptr) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur->val < num)\n            cur = cur->right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur->val > num)\n            cur = cur->left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else\n            break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.java
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode search(int num) {\n    TreeNode cur = root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num)\n            cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else\n            break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.cs
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? Search(int num) {\n    TreeNode? cur = root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur =\n            cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num)\n            cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else\n            break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.go
    /* \u67e5\u627e\u8282\u70b9 */\nfunc (bst *binarySearchTree) search(num int) *TreeNode {\n    node := bst.root\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    for node != nil {\n        if node.Val.(int) < num {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            node = node.Right\n        } else if node.Val.(int) > num {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            node = node.Left\n        } else {\n            // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            break\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return node\n}\n
    binary_search_tree.swift
    /* \u67e5\u627e\u8282\u70b9 */\nfunc search(num: Int) -> TreeNode? {\n    var cur = root\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur != nil {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur!.val < num {\n            cur = cur?.right\n        }\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if cur!.val > num {\n            cur = cur?.left\n        }\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else {\n            break\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur\n}\n
    binary_search_tree.js
    /* \u67e5\u627e\u8282\u70b9 */\nsearch(num) {\n    let cur = this.root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num) cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.ts
    /* \u67e5\u627e\u8282\u70b9 */\nsearch(num: number): TreeNode | null {\n    let cur = this.root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else if (cur.val > num) cur = cur.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        else break;\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.dart
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode? search(int _num) {\n  TreeNode? cur = _root;\n  // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n  while (cur != null) {\n    // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n    if (cur.val < _num)\n      cur = cur.right;\n    // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n    else if (cur.val > _num)\n      cur = cur.left;\n    // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n    else\n      break;\n  }\n  // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n  return cur;\n}\n
    binary_search_tree.rs
    /* \u67e5\u627e\u8282\u70b9 */\npub fn search(&self, num: i32) -> OptionTreeNodeRc {\n    let mut cur = self.root.clone();\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while let Some(node) = cur.clone() {\n        match num.cmp(&node.borrow().val) {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            Ordering::Greater => cur = node.borrow().right.clone(),\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            Ordering::Less => cur = node.borrow().left.clone(),\n            // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            Ordering::Equal => break,\n        }\n    }\n\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    cur\n}\n
    binary_search_tree.c
    /* \u67e5\u627e\u8282\u70b9 */\nTreeNode *search(BinarySearchTree *bst, int num) {\n    TreeNode *cur = bst->root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != NULL) {\n        if (cur->val < num) {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            cur = cur->right;\n        } else if (cur->val > num) {\n            // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            cur = cur->left;\n        } else {\n            // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            break;\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return cur;\n}\n
    binary_search_tree.zig
    // \u67e5\u627e\u8282\u70b9\nfn search(self: *Self, num: T) ?*inc.TreeNode(T) {\n    var cur = self.root;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.?.val < num) {\n            cur = cur.?.right;\n        // \u76ee\u6807\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        } else if (cur.?.val > num) {\n            cur = cur.?.left;\n        // \u627e\u5230\u76ee\u6807\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        } else {\n            break;\n        }\n    }\n    // \u8fd4\u56de\u76ee\u6807\u8282\u70b9\n    return 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 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 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 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\n    if self._root is None:\n        self._root = TreeNode(num)\n        return\n    # \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    cur, pre = self._root, None\n    while cur is not None:\n        # \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if cur.val == num:\n            return\n        pre = cur\n        # \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur.val < num:\n            cur = cur.right\n        # \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else:\n            cur = cur.left\n    # \u63d2\u5165\u8282\u70b9\n    node = TreeNode(num)\n    if pre.val < num:\n        pre.right = node\n    else:\n        pre.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\n    if (root == nullptr) {\n        root = new TreeNode(num);\n        return;\n    }\n    TreeNode *cur = root, *pre = nullptr;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != nullptr) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur->val == num)\n            return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur->val < num)\n            cur = cur->right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur->left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode *node = new TreeNode(num);\n    if (pre->val < num)\n        pre->right = node;\n    else\n        pre->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\n    if (root == null) {\n        root = new TreeNode(num);\n        return;\n    }\n    TreeNode cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val == num)\n            return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode node = new TreeNode(num);\n    if (pre.val < num)\n        pre.right = node;\n    else\n        pre.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\n    if (root == null) {\n        root = new TreeNode(num);\n        return;\n    }\n    TreeNode? cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val == num)\n            return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode node = new(num);\n    if (pre != null) {\n        if (pre.val < num)\n            pre.right = node;\n        else\n            pre.left = node;\n    }\n}\n
    binary_search_tree.go
    /* \u63d2\u5165\u8282\u70b9 */\nfunc (bst *binarySearchTree) insert(num int) {\n    cur := bst.root\n    // \u82e5\u6811\u4e3a\u7a7a\uff0c\u5219\u521d\u59cb\u5316\u6839\u8282\u70b9\n    if cur == nil {\n        bst.root = NewTreeNode(num)\n        return\n    }\n    // \u5f85\u63d2\u5165\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\n    var pre *TreeNode = nil\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    for cur != nil {\n        if cur.Val == num {\n            return\n        }\n        pre = cur\n        if cur.Val.(int) < num {\n            cur = cur.Right\n        } else {\n            cur = cur.Left\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    node := NewTreeNode(num)\n    if pre.Val.(int) < num {\n        pre.Right = node\n    } else {\n        pre.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\n    if root == nil {\n        root = TreeNode(x: num)\n        return\n    }\n    var cur = root\n    var pre: TreeNode?\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur != nil {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if cur!.val == num {\n            return\n        }\n        pre = cur\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur!.val < num {\n            cur = cur?.right\n        }\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else {\n            cur = cur?.left\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    let node = TreeNode(x: num)\n    if pre!.val < num {\n        pre?.right = node\n    } else {\n        pre?.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\n    if (this.root === null) {\n        this.root = new TreeNode(num);\n        return;\n    }\n    let cur = this.root,\n        pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val === num) return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    const node = new TreeNode(num);\n    if (pre.val < num) pre.right = node;\n    else 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\n    if (this.root === null) {\n        this.root = new TreeNode(num);\n        return;\n    }\n    let cur: TreeNode | null = this.root,\n        pre: TreeNode | null = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.val === num) return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u63d2\u5165\u8282\u70b9\n    const node = new TreeNode(num);\n    if (pre!.val < num) pre!.right = node;\n    else 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\n  if (_root == null) {\n    _root = TreeNode(_num);\n    return;\n  }\n  TreeNode? cur = _root;\n  TreeNode? pre = null;\n  // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n  while (cur != null) {\n    // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n    if (cur.val == _num) return;\n    pre = cur;\n    // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n    if (cur.val < _num)\n      cur = cur.right;\n    // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n    else\n      cur = cur.left;\n  }\n  // \u63d2\u5165\u8282\u70b9\n  TreeNode? node = TreeNode(_num);\n  if (pre!.val < _num)\n    pre.right = node;\n  else\n    pre.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\n    if self.root.is_none() {\n        self.root = Some(TreeNode::new(num));\n        return;\n    }\n    let mut cur = self.root.clone();\n    let mut pre = None;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while let Some(node) = cur.clone() {\n        match num.cmp(&node.borrow().val) {\n            // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n            Ordering::Equal => return,\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            Ordering::Greater => {\n                pre = cur.clone();\n                cur = node.borrow().right.clone();\n            }\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            Ordering::Less => {\n                pre = cur.clone();\n                cur = node.borrow().left.clone();\n            }\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    let pre = pre.unwrap();\n    let node = Some(TreeNode::new(num));\n    if num > pre.borrow().val {\n        pre.borrow_mut().right = node;\n    } else {\n        pre.borrow_mut().left = 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\n    if (bst->root == NULL) {\n        bst->root = newTreeNode(num);\n        return;\n    }\n    TreeNode *cur = bst->root, *pre = NULL;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != NULL) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur->val == num) {\n            return;\n        }\n        pre = cur;\n        if (cur->val < num) {\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            cur = cur->right;\n        } else {\n            // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            cur = cur->left;\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    TreeNode *node = newTreeNode(num);\n    if (pre->val < num) {\n        pre->right = node;\n    } else {\n        pre->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\n    if (self.root == null) {\n        self.root = try self.mem_allocator.create(inc.TreeNode(T));\n        return;\n    }\n    var cur = self.root;\n    var pre: ?*inc.TreeNode(T) = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u91cd\u590d\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n        if (cur.?.val == num) return;\n        pre = cur;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.?.val < num) {\n            cur = cur.?.right;\n        // \u63d2\u5165\u4f4d\u7f6e\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        } else {\n            cur = cur.?.left;\n        }\n    }\n    // \u63d2\u5165\u8282\u70b9\n    var node = try self.mem_allocator.create(inc.TreeNode(T));\n    node.init(num);\n    if (pre.?.val < num) {\n        pre.?.right = node;\n    } else {\n        pre.?.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\n    if self._root is None:\n        return\n    # \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    cur, pre = self._root, None\n    while cur is not None:\n        # \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if cur.val == num:\n            break\n        pre = cur\n        # \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur.val < num:\n            cur = cur.right\n        # \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else:\n            cur = cur.left\n    # \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur is None:\n        return\n\n    # \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if 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\n        child = cur.left or cur.right\n        # \u5220\u9664\u8282\u70b9 cur\n        if cur != self._root:\n            if pre.left == cur:\n                pre.left = child\n            else:\n                pre.right = child\n        else:\n            # \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            self._root = child\n    # \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else:\n        # \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        tmp: TreeNode = cur.right\n        while tmp.left is not None:\n            tmp = tmp.left\n        # \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        self.remove(tmp.val)\n        # \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if (root == nullptr)\n        return;\n    TreeNode *cur = root, *pre = nullptr;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != nullptr) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur->val == num)\n            break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur->val < num)\n            cur = cur->right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur->left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == nullptr)\n        return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur->left == nullptr || cur->right == nullptr) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\n        TreeNode *child = cur->left != nullptr ? cur->left : cur->right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur != root) {\n            if (pre->left == cur)\n                pre->left = child;\n            else\n                pre->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        // \u91ca\u653e\u5185\u5b58\n        delete cur;\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\n        TreeNode *tmp = cur->right;\n        while (tmp->left != nullptr) {\n            tmp = tmp->left;\n        }\n        int tmpVal = tmp->val;\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        remove(tmp->val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur->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\n    if (root == null)\n        return;\n    TreeNode cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val == num)\n            break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == null)\n        return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left == null || cur.right == null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        TreeNode child = cur.left != null ? cur.left : cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur != root) {\n            if (pre.left == cur)\n                pre.left = child;\n            else\n                pre.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    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else {\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        TreeNode tmp = cur.right;\n        while (tmp.left != null) {\n            tmp = tmp.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        remove(tmp.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if (root == null)\n        return;\n    TreeNode? cur = root, pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val == num)\n            break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num)\n            cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else\n            cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == null)\n        return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left == null || cur.right == null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        TreeNode? child = cur.left ?? cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur != root) {\n            if (pre!.left == cur)\n                pre.left = child;\n            else\n                pre.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    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else {\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        TreeNode? tmp = cur.right;\n        while (tmp.left != null) {\n            tmp = tmp.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        Remove(tmp.val!.Value);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.val = tmp.val;\n    }\n}\n
    binary_search_tree.go
    /* \u5220\u9664\u8282\u70b9 */\nfunc (bst *binarySearchTree) remove(num int) {\n    cur := bst.root\n    // \u82e5\u6811\u4e3a\u7a7a\uff0c\u76f4\u63a5\u63d0\u524d\u8fd4\u56de\n    if cur == nil {\n        return\n    }\n    // \u5f85\u5220\u9664\u8282\u70b9\u4e4b\u524d\u7684\u8282\u70b9\u4f4d\u7f6e\n    var pre *TreeNode = nil\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    for cur != nil {\n        if cur.Val == num {\n            break\n        }\n        pre = cur\n        if cur.Val.(int) < num {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728\u53f3\u5b50\u6811\u4e2d\n            cur = cur.Right\n        } else {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728\u5de6\u5b50\u6811\u4e2d\n            cur = cur.Left\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur == nil {\n        return\n    }\n    // \u5b50\u8282\u70b9\u6570\u4e3a 0 \u6216 1\n    if cur.Left == nil || cur.Right == nil {\n        var child *TreeNode = nil\n        // \u53d6\u51fa\u5f85\u5220\u9664\u8282\u70b9\u7684\u5b50\u8282\u70b9\n        if cur.Left != nil {\n            child = cur.Left\n        } else {\n            child = cur.Right\n        }\n        // \u5220\u9664\u8282\u70b9 cur\n        if cur != bst.root {\n            if pre.Left == cur {\n                pre.Left = child\n            } else {\n                pre.Right = child\n            }\n        } else {\n            // \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            bst.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\n        tmp := cur.Right\n        for tmp.Left != nil {\n            tmp = tmp.Left\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        bst.remove(tmp.Val.(int))\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if root == nil {\n        return\n    }\n    var cur = root\n    var pre: TreeNode?\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while cur != nil {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if cur!.val == num {\n            break\n        }\n        pre = cur\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if cur!.val < num {\n            cur = cur?.right\n        }\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else {\n            cur = cur?.left\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur == nil {\n        return\n    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if cur?.left == nil || cur?.right == nil {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        let child = cur?.left != nil ? cur?.left : cur?.right\n        // \u5220\u9664\u8282\u70b9 cur\n        if cur !== root {\n            if pre?.left === cur {\n                pre?.left = child\n            } else {\n                pre?.right = child\n            }\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    }\n    // \u5b50\u8282\u70b9\u6570\u91cf = 2\n    else {\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        var tmp = cur?.right\n        while tmp?.left != nil {\n            tmp = tmp?.left\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        remove(num: tmp!.val)\n        // \u7528 tmp \u8986\u76d6 cur\n        cur?.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\n    if (this.root === null) return;\n    let cur = this.root,\n        pre = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val === num) break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur === null) return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left === null || cur.right === null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        const child = cur.left !== null ? cur.left : cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur !== this.root) {\n            if (pre.left === cur) pre.left = child;\n            else pre.right = child;\n        } else {\n            // \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            this.root = child;\n        }\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\n        let tmp = cur.right;\n        while (tmp.left !== null) {\n            tmp = tmp.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        this.remove(tmp.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n    if (this.root === null) return;\n    let cur: TreeNode | null = this.root,\n        pre: TreeNode | null = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur !== null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.val === num) break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.val < num) cur = cur.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        else cur = cur.left;\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur === null) return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.left === null || cur.right === null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        const child: TreeNode | null =\n            cur.left !== null ? cur.left : cur.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (cur !== this.root) {\n            if (pre!.left === cur) pre!.left = child;\n            else pre!.right = child;\n        } else {\n            // \u82e5\u5220\u9664\u8282\u70b9\u4e3a\u6839\u8282\u70b9\uff0c\u5219\u91cd\u65b0\u6307\u5b9a\u6839\u8282\u70b9\n            this.root = child;\n        }\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\n        let tmp: TreeNode | null = cur.right;\n        while (tmp!.left !== null) {\n            tmp = tmp!.left;\n        }\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        this.remove(tmp!.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.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\n  if (_root == null) return;\n  TreeNode? cur = _root;\n  TreeNode? pre = null;\n  // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n  while (cur != null) {\n    // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n    if (cur.val == _num) break;\n    pre = cur;\n    // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n    if (cur.val < _num)\n      cur = cur.right;\n    // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n    else\n      cur = cur.left;\n  }\n  // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u76f4\u63a5\u8fd4\u56de\n  if (cur == null) return;\n  // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n  if (cur.left == null || cur.right == null) {\n    // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n    TreeNode? child = cur.left ?? cur.right;\n    // \u5220\u9664\u8282\u70b9 cur\n    if (cur != _root) {\n      if (pre!.left == cur)\n        pre.left = child;\n      else\n        pre.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\n    TreeNode? tmp = cur.right;\n    while (tmp!.left != null) {\n      tmp = tmp.left;\n    }\n    // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n    remove(tmp.val);\n    // \u7528 tmp \u8986\u76d6 cur\n    cur.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\n    if self.root.is_none() { \n        return; \n    }\n    let mut cur = self.root.clone();\n    let mut pre = None;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while let Some(node) = cur.clone() {\n        match num.cmp(&node.borrow().val) {\n            // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n            Ordering::Equal => break,\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n            Ordering::Greater => {\n                pre = cur.clone();\n                cur = node.borrow().right.clone();\n            }\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n            Ordering::Less => {\n                pre = cur.clone();\n                cur = node.borrow().left.clone();\n            }\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if cur.is_none() {\n        return;\n    }\n    let cur = cur.unwrap();\n    let (left_child, right_child) = (cur.borrow().left.clone(), cur.borrow().right.clone());\n    match (left_child.clone(), right_child.clone()) {\n        // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n        (None, None) | (Some(_), None) | (None, Some(_)) => {\n            // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = nullptr / \u8be5\u5b50\u8282\u70b9\n            let child = left_child.or(right_child);\n            let pre = pre.unwrap();\n            // \u5220\u9664\u8282\u70b9 cur\n            if !Rc::ptr_eq(&cur, self.root.as_ref().unwrap()) {\n                let left = pre.borrow().left.clone();\n                if left.is_some() && Rc::ptr_eq(&left.as_ref().unwrap(), &cur) {\n                    pre.borrow_mut().left = child;\n                } else {\n                    pre.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\n                self.root = child;\n            }\n        }\n        // \u5b50\u8282\u70b9\u6570\u91cf = 2\n        (Some(_), Some(_)) => {\n            // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n            let mut tmp = cur.borrow().right.clone();\n            while let Some(node) = tmp.clone() {\n                if node.borrow().left.is_some() {\n                    tmp = node.borrow().left.clone();\n                } else {\n                    break;\n                }\n            }\n            let tmpval = tmp.unwrap().borrow().val;\n            // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n            self.remove(tmpval);\n            // \u7528 tmp \u8986\u76d6 cur\n            cur.borrow_mut().val = tmpval;\n        }\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\n    if (bst->root == NULL)\n        return;\n    TreeNode *cur = bst->root, *pre = NULL;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != NULL) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur->val == num)\n            break;\n        pre = cur;\n        if (cur->val < num) {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u53f3\u5b50\u6811\u4e2d\n            cur = cur->right;\n        } else {\n            // \u5f85\u5220\u9664\u8282\u70b9\u5728 root \u7684\u5de6\u5b50\u6811\u4e2d\n            cur = cur->left;\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == NULL)\n        return;\n    // \u5224\u65ad\u5f85\u5220\u9664\u8282\u70b9\u662f\u5426\u5b58\u5728\u5b50\u8282\u70b9\n    if (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\n        TreeNode *child = cur->left != NULL ? cur->left : cur->right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (pre->left == cur) {\n            pre->left = child;\n        } else {\n            pre->right = child;\n        }\n        // \u91ca\u653e\u5185\u5b58\n        free(cur);\n    } else {\n        /* \u5b50\u8282\u70b9\u6570\u91cf = 2 */\n        // \u83b7\u53d6\u4e2d\u5e8f\u904d\u5386\u4e2d cur \u7684\u4e0b\u4e00\u4e2a\u8282\u70b9\n        TreeNode *tmp = cur->right;\n        while (tmp->left != NULL) {\n            tmp = tmp->left;\n        }\n        int tmpVal = tmp->val;\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        removeItem(bst, tmp->val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur->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\n    if (self.root == null) return;\n    var cur = self.root;\n    var pre: ?*inc.TreeNode(T) = null;\n    // \u5faa\u73af\u67e5\u627e\uff0c\u8d8a\u8fc7\u53f6\u8282\u70b9\u540e\u8df3\u51fa\n    while (cur != null) {\n        // \u627e\u5230\u5f85\u5220\u9664\u8282\u70b9\uff0c\u8df3\u51fa\u5faa\u73af\n        if (cur.?.val == num) break;\n        pre = cur;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u53f3\u5b50\u6811\u4e2d\n        if (cur.?.val < num) {\n            cur = cur.?.right;\n        // \u5f85\u5220\u9664\u8282\u70b9\u5728 cur \u7684\u5de6\u5b50\u6811\u4e2d\n        } else {\n            cur = cur.?.left;\n        }\n    }\n    // \u82e5\u65e0\u5f85\u5220\u9664\u8282\u70b9\uff0c\u5219\u76f4\u63a5\u8fd4\u56de\n    if (cur == null) return;\n    // \u5b50\u8282\u70b9\u6570\u91cf = 0 or 1\n    if (cur.?.left == null or cur.?.right == null) {\n        // \u5f53\u5b50\u8282\u70b9\u6570\u91cf = 0 / 1 \u65f6\uff0c child = null / \u8be5\u5b50\u8282\u70b9\n        var child = if (cur.?.left != null) cur.?.left else cur.?.right;\n        // \u5220\u9664\u8282\u70b9 cur\n        if (pre.?.left == cur) {\n            pre.?.left = child;\n        } else {\n            pre.?.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\n        var tmp = cur.?.right;\n        while (tmp.?.left != null) {\n            tmp = tmp.?.left;\n        }\n        var tmp_val = tmp.?.val;\n        // \u9012\u5f52\u5220\u9664\u8282\u70b9 tmp\n        self.remove(tmp.?.val);\n        // \u7528 tmp \u8986\u76d6 cur\n        cur.?.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\"\"\"\n    def __init__(self, val: int):\n        self.val: int = val                # \u8282\u70b9\u503c\n        self.left: TreeNode | None = None  # \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n        self.right: TreeNode | None = None # \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\n    int val;          // \u8282\u70b9\u503c\n    TreeNode *left;   // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    TreeNode *right;  // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n};\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    int val;         // \u8282\u70b9\u503c\n    TreeNode left;   // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    TreeNode right;  // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n    TreeNode(int x) { val = x; }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode(int? x) {\n    public int? val = x;    // \u8282\u70b9\u503c\n    public TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    public TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntype TreeNode struct {\n    Val   int\n    Left  *TreeNode\n    Right *TreeNode\n}\n/* \u6784\u9020\u65b9\u6cd5 */\nfunc NewTreeNode(v int) *TreeNode {\n    return &TreeNode{\n        Left:  nil, // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n        Right: nil, // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n        Val:   v,   // \u8282\u70b9\u503c\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    var val: Int // \u8282\u70b9\u503c\n    var left: TreeNode? // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    var right: TreeNode? // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n\n    init(x: Int) {\n        val = x\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val; // \u8282\u70b9\u503c\n    left; // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n    constructor(val, left, right) {\n        this.val = val === undefined ? 0 : val;\n        this.left = left === undefined ? null : left;\n        this.right = right === undefined ? null : right;\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n    val: number;\n    left: TreeNode | null;\n    right: TreeNode | null;\n\n    constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {\n        this.val = val === undefined ? 0 : val; // \u8282\u70b9\u503c\n        this.left = left === undefined ? null : left; // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n        this.right = right === undefined ? null : right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7c7b */\nclass TreeNode {\n  int val;         // \u8282\u70b9\u503c\n  TreeNode? left;  // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n  TreeNode? right; // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n  TreeNode(this.val, [this.left, this.right]);\n}\n
    use std::rc::Rc;\nuse std::cell::RefCell;\n\n/* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\nstruct TreeNode {\n    val: i32,                               // \u8282\u70b9\u503c\n    left: Option<Rc<RefCell<TreeNode>>>,    // \u5de6\u5b50\u8282\u70b9\u5f15\u7528\n    right: Option<Rc<RefCell<TreeNode>>>,   // \u53f3\u5b50\u8282\u70b9\u5f15\u7528\n}\n\nimpl TreeNode {\n    /* \u6784\u9020\u65b9\u6cd5 */\n    fn new(val: i32) -> Rc<RefCell<Self>> {\n        Rc::new(RefCell::new(Self {\n            val,\n            left: None,\n            right: None\n        }))\n    }\n}\n
    /* \u4e8c\u53c9\u6811\u8282\u70b9\u7ed3\u6784\u4f53 */\ntypedef struct TreeNode {\n    int val;                // \u8282\u70b9\u503c\n    int height;             // \u8282\u70b9\u9ad8\u5ea6\n    struct TreeNode *left;  // \u5de6\u5b50\u8282\u70b9\u6307\u9488\n    struct TreeNode *right; // \u53f3\u5b50\u8282\u70b9\u6307\u9488\n} TreeNode;\n\n/* \u6784\u9020\u51fd\u6570 */\nTreeNode *newTreeNode(int val) {\n    TreeNode *node;\n\n    node = (TreeNode *)malloc(sizeof(TreeNode));\n    node->val = val;\n    node->height = 0;\n    node->left = NULL;\n    node->right = NULL;\n    return 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 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),\n    n2 = new TreeNode(2),\n    n3 = new TreeNode(3),\n    n4 = new TreeNode(4),\n    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.ts
    /* \u521d\u59cb\u5316\u4e8c\u53c9\u6811 */\n// \u521d\u59cb\u5316\u8282\u70b9\nlet n1 = new TreeNode(1),\n    n2 = new TreeNode(2),\n    n3 = new TreeNode(3),\n    n4 = new TreeNode(4),\n    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.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\u300d\uff0c\u4e5f\u79f0\u300c\u5e7f\u5ea6\u4f18\u5148\u641c\u7d22 breadth-first search, 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\n    queue: deque[TreeNode] = deque()\n    queue.append(root)\n    # \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    res = []\n    while queue:\n        node: TreeNode = queue.popleft()  # \u961f\u5217\u51fa\u961f\n        res.append(node.val)  # \u4fdd\u5b58\u8282\u70b9\u503c\n        if node.left is not None:\n            queue.append(node.left)  # \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if node.right is not None:\n            queue.append(node.right)  # \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    return 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\n    queue<TreeNode *> queue;\n    queue.push(root);\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    vector<int> vec;\n    while (!queue.empty()) {\n        TreeNode *node = queue.front();\n        queue.pop();              // \u961f\u5217\u51fa\u961f\n        vec.push_back(node->val); // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node->left != nullptr)\n            queue.push(node->left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node->right != nullptr)\n            queue.push(node->right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    Queue<TreeNode> queue = new LinkedList<>();\n    queue.add(root);\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    List<Integer> list = new ArrayList<>();\n    while (!queue.isEmpty()) {\n        TreeNode node = queue.poll(); // \u961f\u5217\u51fa\u961f\n        list.add(node.val);           // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left != null)\n            queue.offer(node.left);   // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node.right != null)\n            queue.offer(node.right);  // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    Queue<TreeNode> queue = new();\n    queue.Enqueue(root);\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    List<int> list = [];\n    while (queue.Count != 0) {\n        TreeNode node = queue.Dequeue(); // \u961f\u5217\u51fa\u961f\n        list.Add(node.val!.Value);       // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left != null)\n            queue.Enqueue(node.left);    // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node.right != null)\n            queue.Enqueue(node.right);   // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    queue := list.New()\n    queue.PushBack(root)\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5207\u7247\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    nums := make([]any, 0)\n    for queue.Len() > 0 {\n        // \u961f\u5217\u51fa\u961f\n        node := queue.Remove(queue.Front()).(*TreeNode)\n        // \u4fdd\u5b58\u8282\u70b9\u503c\n        nums = append(nums, node.Val)\n        if node.Left != nil {\n            // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n            queue.PushBack(node.Left)\n        }\n        if node.Right != nil {\n            // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n            queue.PushBack(node.Right)\n        }\n    }\n    return 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\n    var queue: [TreeNode] = [root]\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    var list: [Int] = []\n    while !queue.isEmpty {\n        let node = queue.removeFirst() // \u961f\u5217\u51fa\u961f\n        list.append(node.val) // \u4fdd\u5b58\u8282\u70b9\u503c\n        if let left = node.left {\n            queue.append(left) // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if let right = node.right {\n            queue.append(right) // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        }\n    }\n    return 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\n    const queue = [root];\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    const list = [];\n    while (queue.length) {\n        let node = queue.shift(); // \u961f\u5217\u51fa\u961f\n        list.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left) queue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        if (node.right) queue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n    }\n    return 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\n    const queue = [root];\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    const list: number[] = [];\n    while (queue.length) {\n        let node = queue.shift() as TreeNode; // \u961f\u5217\u51fa\u961f\n        list.push(node.val); // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left) {\n            queue.push(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if (node.right) {\n            queue.push(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        }\n    }\n    return 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\n  Queue<TreeNode?> queue = Queue();\n  queue.add(root);\n  // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n  List<int> res = [];\n  while (queue.isNotEmpty) {\n    TreeNode? node = queue.removeFirst(); // \u961f\u5217\u51fa\u961f\n    res.add(node!.val); // \u4fdd\u5b58\u8282\u70b9\u503c\n    if (node.left != null) queue.add(node.left); // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n    if (node.right != null) queue.add(node.right); // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n  }\n  return 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\n    let mut que = VecDeque::new();\n    que.push_back(Rc::clone(&root));\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    let mut vec = Vec::new();\n\n    while let Some(node) = que.pop_front() {                 // \u961f\u5217\u51fa\u961f\n        vec.push(node.borrow().val);                         // \u4fdd\u5b58\u8282\u70b9\u503c\n        if let Some(left) = node.borrow().left.as_ref() {\n            que.push_back(Rc::clone(left));                  // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if let Some(right) = node.borrow().right.as_ref() {\n            que.push_back(Rc::clone(right));                 // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        };\n    }\n    vec\n}\n
    binary_tree_bfs.c
    /* \u5c42\u5e8f\u904d\u5386 */\nint *levelOrder(TreeNode *root, int *size) {\n    /* \u8f85\u52a9\u961f\u5217 */\n    int front, rear;\n    int index, *arr;\n    TreeNode *node;\n    TreeNode **queue;\n\n    /* \u8f85\u52a9\u961f\u5217 */\n    queue = (TreeNode **)malloc(sizeof(TreeNode *) * MAX_SIZE);\n    // \u961f\u5217\u6307\u9488\n    front = 0, rear = 0;\n    // \u52a0\u5165\u6839\u8282\u70b9\n    queue[rear++] = root;\n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    /* \u8f85\u52a9\u6570\u7ec4 */\n    arr = (int *)malloc(sizeof(int) * MAX_SIZE);\n    // \u6570\u7ec4\u6307\u9488\n    index = 0;\n    while (front < rear) {\n        // \u961f\u5217\u51fa\u961f\n        node = queue[front++];\n        // \u4fdd\u5b58\u8282\u70b9\u503c\n        arr[index++] = node->val;\n        if (node->left != NULL) {\n            // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n            queue[rear++] = node->left;\n        }\n        if (node->right != NULL) {\n            // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n            queue[rear++] = node->right;\n        }\n    }\n    // \u66f4\u65b0\u6570\u7ec4\u957f\u5ea6\u7684\u503c\n    *size = index;\n    arr = realloc(arr, sizeof(int) * (*size));\n\n    // \u91ca\u653e\u8f85\u52a9\u6570\u7ec4\u7a7a\u95f4\n    free(queue);\n    return 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\n    const L = std.TailQueue(*inc.TreeNode(T));\n    var queue = L{};\n    var root_node = try mem_allocator.create(L.Node);\n    root_node.data = root;\n    queue.append(root_node); \n    // \u521d\u59cb\u5316\u4e00\u4e2a\u5217\u8868\uff0c\u7528\u4e8e\u4fdd\u5b58\u904d\u5386\u5e8f\u5217\n    var list = std.ArrayList(T).init(std.heap.page_allocator);\n    while (queue.len > 0) {\n        var queue_node = queue.popFirst().?;    // \u961f\u5217\u51fa\u961f\n        var node = queue_node.data;\n        try list.append(node.val);              // \u4fdd\u5b58\u8282\u70b9\u503c\n        if (node.left != null) {\n            var tmp_node = try mem_allocator.create(L.Node);\n            tmp_node.data = node.left.?;\n            queue.append(tmp_node);             // \u5de6\u5b50\u8282\u70b9\u5165\u961f\n        }\n        if (node.right != null) {\n            var tmp_node = try mem_allocator.create(L.Node);\n            tmp_node.data = node.right.?;\n            queue.append(tmp_node);             // \u53f3\u5b50\u8282\u70b9\u5165\u961f\n        }        \n    }\n    return list;\n}\n
    "},{"location":"chapter_tree/binary_tree_traversal/#2","title":"2. \u00a0 \u590d\u6742\u5ea6\u5206\u6790","text":"
    • \u65f6\u95f4\u590d\u6742\u5ea6\u4e3a \\(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\u4e3a \\(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\u300d\uff0c\u4e5f\u79f0\u300c\u6df1\u5ea6\u4f18\u5148\u641c\u7d22 depth-first search, 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\"\"\"\n    if root is None:\n        return\n    # \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    res.append(root.val)\n    pre_order(root=root.left)\n    pre_order(root=root.right)\n\ndef in_order(root: TreeNode | None):\n    \"\"\"\u4e2d\u5e8f\u904d\u5386\"\"\"\n    if root is None:\n        return\n    # \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    in_order(root=root.left)\n    res.append(root.val)\n    in_order(root=root.right)\n\ndef post_order(root: TreeNode | None):\n    \"\"\"\u540e\u5e8f\u904d\u5386\"\"\"\n    if root is None:\n        return\n    # \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    post_order(root=root.left)\n    post_order(root=root.right)\n    res.append(root.val)\n
    binary_tree_dfs.cpp
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root) {\n    if (root == nullptr)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    vec.push_back(root->val);\n    preOrder(root->left);\n    preOrder(root->right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root) {\n    if (root == nullptr)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root->left);\n    vec.push_back(root->val);\n    inOrder(root->right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root) {\n    if (root == nullptr)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root->left);\n    postOrder(root->right);\n    vec.push_back(root->val);\n}\n
    binary_tree_dfs.java
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode root) {\n    if (root == null)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.add(root.val);\n    preOrder(root.left);\n    preOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode root) {\n    if (root == null)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root.left);\n    list.add(root.val);\n    inOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode root) {\n    if (root == null)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root.left);\n    postOrder(root.right);\n    list.add(root.val);\n}\n
    binary_tree_dfs.cs
    /* \u524d\u5e8f\u904d\u5386 */\nvoid PreOrder(TreeNode? root) {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.Add(root.val!.Value);\n    PreOrder(root.left);\n    PreOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid InOrder(TreeNode? root) {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    InOrder(root.left);\n    list.Add(root.val!.Value);\n    InOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid PostOrder(TreeNode? root) {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    PostOrder(root.left);\n    PostOrder(root.right);\n    list.Add(root.val!.Value);\n}\n
    binary_tree_dfs.go
    /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(node *TreeNode) {\n    if node == nil {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    nums = append(nums, node.Val)\n    preOrder(node.Left)\n    preOrder(node.Right)\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(node *TreeNode) {\n    if node == nil {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(node.Left)\n    nums = append(nums, node.Val)\n    inOrder(node.Right)\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(node *TreeNode) {\n    if node == nil {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(node.Left)\n    postOrder(node.Right)\n    nums = append(nums, node.Val)\n}\n
    binary_tree_dfs.swift
    /* \u524d\u5e8f\u904d\u5386 */\nfunc preOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.append(root.val)\n    preOrder(root: root.left)\n    preOrder(root: root.right)\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunc inOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root: root.left)\n    list.append(root.val)\n    inOrder(root: root.right)\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunc postOrder(root: TreeNode?) {\n    guard let root = root else {\n        return\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root: root.left)\n    postOrder(root: root.right)\n    list.append(root.val)\n}\n
    binary_tree_dfs.js
    /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root) {\n    if (root === null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.push(root.val);\n    preOrder(root.left);\n    preOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root) {\n    if (root === null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root.left);\n    list.push(root.val);\n    inOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root) {\n    if (root === null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root.left);\n    postOrder(root.right);\n    list.push(root.val);\n}\n
    binary_tree_dfs.ts
    /* \u524d\u5e8f\u904d\u5386 */\nfunction preOrder(root: TreeNode | null): void {\n    if (root === null) {\n        return;\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    list.push(root.val);\n    preOrder(root.left);\n    preOrder(root.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfunction inOrder(root: TreeNode | null): void {\n    if (root === null) {\n        return;\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root.left);\n    list.push(root.val);\n    inOrder(root.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfunction postOrder(root: TreeNode | null): void {\n    if (root === null) {\n        return;\n    }\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root.left);\n    postOrder(root.right);\n    list.push(root.val);\n}\n
    binary_tree_dfs.dart
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode? node) {\n  if (node == null) return;\n  // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n  list.add(node.val);\n  preOrder(node.left);\n  preOrder(node.right);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode? node) {\n  if (node == null) return;\n  // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n  inOrder(node.left);\n  list.add(node.val);\n  inOrder(node.right);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode? node) {\n  if (node == null) return;\n  // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n  postOrder(node.left);\n  postOrder(node.right);\n  list.add(node.val);\n}\n
    binary_tree_dfs.rs
    /* \u524d\u5e8f\u904d\u5386 */\nfn pre_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\n    let mut result = vec![];\n\n    if let Some(node) = root {\n        // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n        result.push(node.borrow().val);\n        result.append(&mut pre_order(node.borrow().left.as_ref()));\n        result.append(&mut pre_order(node.borrow().right.as_ref()));\n    }\n    result\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nfn in_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\n    let mut result = vec![];\n\n    if let Some(node) = root {\n        // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n        result.append(&mut in_order(node.borrow().left.as_ref()));\n        result.push(node.borrow().val);\n        result.append(&mut in_order(node.borrow().right.as_ref()));\n    }\n    result\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nfn post_order(root: Option<&Rc<RefCell<TreeNode>>>) -> Vec<i32> {\n    let mut result = vec![];\n\n    if let Some(node) = root {\n        // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n        result.append(&mut post_order(node.borrow().left.as_ref()));\n        result.append(&mut post_order(node.borrow().right.as_ref()));\n        result.push(node.borrow().val);\n    }\n    result\n}\n
    binary_tree_dfs.c
    /* \u524d\u5e8f\u904d\u5386 */\nvoid preOrder(TreeNode *root, int *size) {\n    if (root == NULL)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    arr[(*size)++] = root->val;\n    preOrder(root->left, size);\n    preOrder(root->right, size);\n}\n\n/* \u4e2d\u5e8f\u904d\u5386 */\nvoid inOrder(TreeNode *root, int *size) {\n    if (root == NULL)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    inOrder(root->left, size);\n    arr[(*size)++] = root->val;\n    inOrder(root->right, size);\n}\n\n/* \u540e\u5e8f\u904d\u5386 */\nvoid postOrder(TreeNode *root, int *size) {\n    if (root == NULL)\n        return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    postOrder(root->left, size);\n    postOrder(root->right, size);\n    arr[(*size)++] = root->val;\n}\n
    binary_tree_dfs.zig
    // \u524d\u5e8f\u904d\u5386\nfn preOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u6839\u8282\u70b9 -> \u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811\n    try list.append(root.?.val);\n    try preOrder(T, root.?.left);\n    try preOrder(T, root.?.right);\n}\n\n// \u4e2d\u5e8f\u904d\u5386\nfn inOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u6839\u8282\u70b9 -> \u53f3\u5b50\u6811\n    try inOrder(T, root.?.left);\n    try list.append(root.?.val);\n    try inOrder(T, root.?.right);\n}\n\n// \u540e\u5e8f\u904d\u5386\nfn postOrder(comptime T: type, root: ?*inc.TreeNode(T)) !void {\n    if (root == null) return;\n    // \u8bbf\u95ee\u4f18\u5148\u7ea7\uff1a\u5de6\u5b50\u6811 -> \u53f3\u5b50\u6811 -> \u6839\u8282\u70b9\n    try postOrder(T, root.?.left);\n    try postOrder(T, root.?.right);\n    try 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\u4e3a \\(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\u4e3a \\(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 b/sitemap.xml index be9110633..d60927237 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -2,522 +2,522 @@ https://www.hello-algo.com/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_appendix/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_appendix/contribution/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_appendix/installation/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_appendix/terminology/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_array_and_linkedlist/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_array_and_linkedlist/array/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_array_and_linkedlist/linked_list/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_array_and_linkedlist/list/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_array_and_linkedlist/ram_and_cache/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_array_and_linkedlist/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_backtracking/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_backtracking/backtracking_algorithm/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_backtracking/n_queens_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_backtracking/permutations_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_backtracking/subset_sum_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_backtracking/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_computational_complexity/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_computational_complexity/iteration_and_recursion/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_computational_complexity/performance_evaluation/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_computational_complexity/space_complexity/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_computational_complexity/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_computational_complexity/time_complexity/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_data_structure/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_data_structure/basic_data_types/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_data_structure/character_encoding/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_data_structure/classification_of_data_structure/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_data_structure/number_encoding/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_data_structure/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_divide_and_conquer/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_divide_and_conquer/binary_search_recur/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_divide_and_conquer/build_binary_tree_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_divide_and_conquer/divide_and_conquer/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_divide_and_conquer/hanota_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_divide_and_conquer/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/dp_problem_features/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/dp_solution_pipeline/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/edit_distance_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/intro_to_dynamic_programming/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/knapsack_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_dynamic_programming/unbounded_knapsack_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_graph/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_graph/graph/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_graph/graph_operations/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_graph/graph_traversal/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_graph/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_greedy/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_greedy/fractional_knapsack_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_greedy/greedy_algorithm/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_greedy/max_capacity_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_greedy/max_product_cutting_problem/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_greedy/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_hashing/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_hashing/hash_algorithm/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_hashing/hash_collision/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_hashing/hash_map/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_hashing/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_heap/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_heap/build_heap/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_heap/heap/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_heap/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_heap/top_k/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_introduction/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_introduction/algorithms_are_everywhere/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_introduction/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_introduction/what_is_dsa/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_preface/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_preface/about_the_book/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_preface/suggestions/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_preface/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_reference/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/binary_search/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/binary_search_edge/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/binary_search_insertion/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/replace_linear_by_hashing/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/searching_algorithm_revisited/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_searching/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/bubble_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/bucket_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/counting_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/heap_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/insertion_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/merge_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/quick_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/radix_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/selection_sort/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/sorting_algorithm/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_sorting/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_stack_and_queue/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_stack_and_queue/deque/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_stack_and_queue/queue/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_stack_and_queue/stack/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_stack_and_queue/summary/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/array_representation_of_tree/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/avl_tree/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/binary_search_tree/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/binary_tree/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/binary_tree_traversal/ - 2024-01-02 + 2024-01-03 daily https://www.hello-algo.com/chapter_tree/summary/ - 2024-01-02 + 2024-01-03 daily \ No newline at end of file diff --git a/sitemap.xml.gz b/sitemap.xml.gz index 74294689c4282e2fcf1450e02671b48f19c31286..3fcb15f42fa90012df2680ebfbb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?xaA<%H;QHk7fhDRCf}wJ+DC+UUGU3OSpjYC3Rv6T(u>V`Cd`a(VeE%^k zrt9{PbwPqWIYQd2ND?$aB2Sa0!5DsgKf&my;_yNE*g}8*fnS15b*RTkoHG16+(Jjm zEfdlLYSN&hTuB?sXq$+Kq zeQA2kd8GH!=QGxLpN$W)Jx|>BM{xb9!n3So{Sl>l!vt0MSy8taZ0G(aidO z$7@&miP&c<2+4HVEOFZ-$H>VCn1f$lxLFrGp!?J2$+<9%|F3)k$+|;xEA-+2Dk)&_ X8^GC#aHV*~|9&dIRFy52M*9CBT7(yG diff --git a/chapter_hashing/hash_collision/index.html b/chapter_hashing/hash_collision/index.html index 9991db1f9..47bb588ca 100644 --- a/chapter_hashing/hash_collision/index.html +++ b/chapter_hashing/hash_collision/index.html @@ -6305,7 +6305,7 @@ // 若找到键值对,则覆盖 val 并返回 if (hashMap->buckets[index] != NULL && hashMap->buckets[index] != hashMap->TOMBSTONE) { free(hashMap->buckets[index]->val); - hashMap->buckets[index]->val = (char *)malloc(sizeof(strlen(val + 1))); + hashMap->buckets[index]->val = (char *)malloc(sizeof(strlen(val) + 1)); strcpy(hashMap->buckets[index]->val, val); hashMap->buckets[index]->val[strlen(val)] = '\0'; return; @@ -6313,7 +6313,7 @@ // 若键值对不存在,则添加该键值对 Pair *pair = (Pair *)malloc(sizeof(Pair)); pair->key = key; - pair->val = (char *)malloc(sizeof(strlen(val + 1))); + pair->val = (char *)malloc(sizeof(strlen(val) + 1)); strcpy(pair->val, val); pair->val[strlen(val)] = '\0'; diff --git a/chapter_preface/about_the_book.assets/hello_algo_mindmap.jpg b/chapter_preface/about_the_book.assets/hello_algo_mindmap.jpg deleted file mode 100644 index 9b0727f47f1daa45f38f01c67c23fbcb42d87f71..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 164629 zcmeFZXH=WXvM4GWXX5}SnP`K_IcFH#1d~lRc?bf70D;Ka0UMJIBF8aFfIu=igNY(z z5F&{TA_zndB41|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