{"id":112221,"date":"2026-10-02T21:48:53","date_gmt":"2026-10-02T13:48:53","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/112221.html"},"modified":"2026-10-02T21:48:53","modified_gmt":"2026-10-02T13:48:53","slug":"%ef%bc%88%e4%b8%89%ef%bc%89%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%8e%e7%ae%97%e6%b3%95-%e7%bb%8f%e5%85%b8%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/112221.html","title":{"rendered":"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5"},"content":{"rendered":"<h3>&#x1f5c2;\ufe0f \u4e00\u3001 \u54c8\u5e0c\u8868&#xff1a;O(1) \u795e\u8bdd\u7684\u7f14\u9020\u8005\u4e0e\u51b2\u7a81\u89e3\u51b3<\/h3>\n<h4>1. \u54c8\u5e0c\u8868\u7684\u539f\u7406\u662f\u4ec0\u4e48&#xff1f;<\/h4>\n<p>\u54c8\u5e0c\u8868&#xff08;Hash Table&#xff09;\u662f\u4e00\u79cd\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u628a\u952e&#xff08;key&#xff09;\u6620\u5c04\u5230\u6570\u7ec4\u4e0b\u6807&#xff0c;\u4ece\u800c\u5728\u5e73\u5747 O(1) \u65f6\u95f4\u5185\u5b8c\u6210\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\u7684\u6570\u636e\u7ed3\u6784\u3002<br \/>\n\u6838\u5fc3\u539f\u7406\u56db\u6b65\u8d70&#xff1a;<\/p>\n<li>\n<p>\u51c6\u5907\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u4f5c\u4e3a\u201c\u6876\u6570\u7ec4\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528\u54c8\u5e0c\u51fd\u6570 hash(key) \u628a\u952e\u6620\u5c04\u6210\u4e00\u4e2a\u6574\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u7528\u8fd9\u4e2a\u6574\u6570\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21&#xff08;\u6216\u4f4d\u8fd0\u7b97&#xff09;\u5f97\u5230\u6876\u4e0b\u6807\u3002<\/p>\n<\/li>\n<li>\n<p>\u628a\u952e\u503c\u5bf9\u653e\u5230\u8fd9\u4e2a\u6876\u91cc\u3002<\/p>\n<\/li>\n<h4>2. \u54c8\u5e0c\u51b2\u7a81\u600e\u4e48\u89e3\u51b3&#xff1f;<\/h4>\n<p>\u4e0d\u540c\u7684 key \u7ecf\u8fc7\u54c8\u5e0c\u51fd\u6570\u540e\u53ef\u80fd\u6620\u5c04\u5230\u540c\u4e00\u4e2a\u4e0b\u6807&#xff0c;\u8fd9\u5c31\u662f\u54c8\u5e0c\u51b2\u7a81&#xff0c;\u65e0\u6cd5\u5b8c\u5168\u907f\u514d\u3002\u4e3b\u8981\u6709\u4e24\u5927\u89e3\u51b3\u65b9\u6848&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u94fe\u5730\u5740\u6cd5&#xff08;\u62c9\u94fe\u6cd5&#xff09;&#xff1a;\u6bcf\u4e2a\u6876\u91cc\u6302\u4e00\u4e2a\u94fe\u8868&#xff08;\u6216\u7ea2\u9ed1\u6811&#xff09;&#xff0c;\u51b2\u7a81\u7684\u5143\u7d20\u90fd\u6302\u5728\u5bf9\u5e94\u6876\u7684\u94fe\u8868\u4e0a\u3002Java HashMap \u548c Redis \u7684 dict \u90fd\u7528\u8fd9\u79cd\u65b9\u5f0f\u3002\u6ce8\u610f\u70b9&#xff1a;JDK 1.8 \u4e4b\u540e&#xff0c;\u5f53\u67d0\u4e2a\u6876\u7684\u94fe\u8868\u957f\u5ea6 \u2265 8 \u4e14\u6570\u7ec4\u957f\u5ea6 \u2265 64 \u65f6&#xff0c;\u94fe\u8868\u4f1a\u8f6c\u6210\u7ea2\u9ed1\u6811&#xff0c;\u8fdb\u4e00\u6b65\u4f18\u5316\u6700\u574f\u60c5\u51b5\u4e0b\u7684\u67e5\u627e\u3002<\/p>\n<\/li>\n<li>\n<p>\u5f00\u653e\u5bfb\u5740\u6cd5&#xff1a;\u51b2\u7a81\u65f6\u6309\u4e00\u5b9a\u89c4\u5219\u5728\u6570\u7ec4\u91cc\u5bfb\u627e\u4e0b\u4e00\u4e2a\u7a7a\u4f4d\u3002\u5e38\u89c1\u63a2\u6d4b\u65b9\u5f0f\u6709\u7ebf\u6027\u63a2\u6d4b&#xff08;i, i&#043;1, i&#043;2&#8230;&#xff09;\u3001\u4e8c\u6b21\u63a2\u6d4b&#xff08;i, i&#043;1\u00b2, i&#043;2\u00b2&#8230;&#xff09;\u3001\u53cc\u91cd\u54c8\u5e0c\u3002Java \u7684 ThreadLocalMap \u5c31\u662f\u7528\u7ebf\u6027\u63a2\u6d4b\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>3. \u8d1f\u8f7d\u56e0\u5b50&#xff08;Load Factor&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u516c\u5f0f&#xff1a;\u5143\u7d20\u6570\u91cf \/ \u6876\u6570\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d1f\u8f7d\u56e0\u5b50\u8d8a\u5927\u51b2\u7a81\u8d8a\u591a\u3002Java HashMap \u9ed8\u8ba4 0.75&#xff0c;\u8d85\u8fc7\u5c31\u89e6\u53d1\u6269\u5bb9&#xff08;rehash&#xff09;&#xff0c;\u4ee5\u7ef4\u6301\u5e73\u5747 O(1) \u7684\u67e5\u627e\u6027\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>&#x1f9e9; \u4e8c\u3001 \u5f52\u5e76\u6392\u5e8f&#xff1a;\u5206\u6cbb\u601d\u60f3\u7684\u5b8c\u7f8e\u4f53\u73b0<\/h3>\n<h4>1. \u539f\u7406\u4e0e\u5b9e\u73b0<\/h4>\n<p>\u5f52\u5e76\u6392\u5e8f\u662f\u4e00\u79cd\u5178\u578b\u7684\u5206\u6cbb\u7b97\u6cd5&#xff0c;\u601d\u60f3\u975e\u5e38\u6e05\u6670&#xff0c;\u5c31\u662f\u201c\u5206\u3001\u6cbb\u3001\u5408\u201d\u4e09\u6b65&#xff1a;<\/p>\n<li>\n<p>\u5206&#xff1a;\u628a\u6570\u7ec4\u4ece\u4e2d\u95f4\u4e00\u5206\u4e3a\u4e8c&#xff0c;\u5206\u5230\u5e95\u3002<\/p>\n<\/li>\n<li>\n<p>\u6cbb&#xff1a;\u9012\u5f52\u5730\u5bf9\u4e24\u534a\u5206\u522b\u6392\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5408&#xff1a;\u628a\u4e24\u4e2a\u5df2\u6392\u5e8f\u7684\u5b50\u6570\u7ec4\u5408\u5e76\u6210\u4e00\u4e2a\u6709\u5e8f\u6570\u7ec4\u3002<\/p>\n<\/li>\n<h4>2. \u590d\u6742\u5ea6\u4e0e\u7279\u6027<\/h4>\n<ul>\n<li>\n<p>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;\u6700\u597d\u3001\u6700\u574f\u3001\u5e73\u5747\u90fd\u662f O(n log n)&#xff08;\u5171 log n \u5c42\u9012\u5f52&#xff0c;\u6bcf\u5c42\u5408\u5e76\u603b\u5171\u5904\u7406 n \u4e2a\u5143\u7d20&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(n)&#xff08;\u9700\u8981\u989d\u5916\u7684\u4e34\u65f6\u6570\u7ec4\u5b58\u653e\u5408\u5e76\u7ed3\u679c&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u7a33\u5b9a\u6027&#xff1a;\u7a33\u5b9a\u6392\u5e8f&#xff0c;\u5408\u5e76\u65f6\u76f8\u540c\u5143\u7d20\u6309\u539f\u59cb\u987a\u5e8f\u653e\u5165\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>3. \u5bf9\u6bd4\u5feb\u6392\u4e0e\u5e94\u7528\u573a\u666f<\/h4>\n<ul>\n<li>\n<p>\u76f8\u6bd4\u5feb\u6392\u7684\u4f18\u52bf&#xff1a;\u7a33\u5b9a\u3001\u6700\u574f\u60c5\u51b5\u4e5f\u662f O(n log n)&#xff08;\u5feb\u6392\u6700\u574f\u662f O(n\u00b2)&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u76f8\u6bd4\u5feb\u6392\u7684\u52a3\u52bf&#xff1a;\u9700\u8981 O(n) \u989d\u5916\u7a7a\u95f4&#xff0c;\u4e0d\u662f\u539f\u5730\u6392\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5178\u578b\u5e94\u7528\u573a\u666f&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5916\u90e8\u6392\u5e8f&#xff08;\u5185\u5b58\u653e\u4e0d\u4e0b\u7684\u6d77\u91cf\u6570\u636e&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u94fe\u8868\u6392\u5e8f&#xff08;\u5bf9\u94fe\u8868\u975e\u5e38\u53cb\u597d&#xff0c;\u7a7a\u95f4\u53ef\u4ee5\u505a\u5230 O(1)&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u9700\u8981\u7a33\u5b9a\u6027\u7684\u4e1a\u52a1\u573a\u666f\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;vector&gt;<\/p>\n<p>\/\/ \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u5b50\u6570\u7ec4<br \/>\nvoid merge(vector&lt;int&gt;&amp; arr, int left, int mid, int right) {<br \/>\n    vector&lt;int&gt; temp(right &#8211; left &#043; 1);<br \/>\n    int i &#061; left, j &#061; mid &#043; 1, k &#061; 0;<\/p>\n<p>    while (i &lt;&#061; mid &amp;&amp; j &lt;&#061; right) {<br \/>\n        \/\/ \u6ce8\u610f&#xff1a;\u8fd9\u91cc\u7528 &lt;&#061; \u4fdd\u8bc1\u7a33\u5b9a\u6027<br \/>\n        if (arr[i] &lt;&#061; arr[j]) {<br \/>\n            temp[k&#043;&#043;] &#061; arr[i&#043;&#043;];<br \/>\n        } else {<br \/>\n            temp[k&#043;&#043;] &#061; arr[j&#043;&#043;];<br \/>\n        }<br \/>\n    }<br \/>\n    while (i &lt;&#061; mid) temp[k&#043;&#043;] &#061; arr[i&#043;&#043;];<br \/>\n    while (j &lt;&#061; right) temp[k&#043;&#043;] &#061; arr[j&#043;&#043;];<\/p>\n<p>    \/\/ \u5c06\u4e34\u65f6\u6570\u7ec4\u62f7\u8d1d\u56de\u539f\u6570\u7ec4<br \/>\n    for (int p &#061; 0; p &lt; k; &#043;&#043;p) {<br \/>\n        arr[left &#043; p] &#061; temp[p];<br \/>\n    }<br \/>\n}<\/p>\n<p>void mergeSort(vector&lt;int&gt;&amp; arr, int left, int right) {<br \/>\n    if (left &gt;&#061; right) return;<br \/>\n    int mid &#061; left &#043; (right &#8211; left) \/ 2;<br \/>\n    mergeSort(arr, left, mid);       \/\/ \u9012\u5f52\u6392\u5e8f\u5de6\u534a<br \/>\n    mergeSort(arr, mid &#043; 1, right);  \/\/ \u9012\u5f52\u6392\u5e8f\u53f3\u534a<br \/>\n    merge(arr, left, mid, right);    \/\/ \u5408\u5e76<br \/>\n}<\/p>\n<h3>\u00a0\u4e09\u3001 \u4e8c\u5206\u67e5\u627e&#xff1a;\u601d\u8def\u5f88\u7b80\u5355&#xff0c;\u7ec6\u8282\u662f\u9b54\u9b3c<\/h3>\n<h4>1. \u6838\u5fc3\u601d\u60f3\u4e0e\u6807\u51c6\u5b9e\u73b0<\/h4>\n<p>\u4e8c\u5206\u67e5\u627e\u662f\u5bf9\u6709\u5e8f\u6570\u7ec4\u8fdb\u884c\u67e5\u627e\u7684\u7ecf\u5178\u7b97\u6cd5&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6 O(log n)\u3002\u6838\u5fc3\u601d\u60f3\u662f\u6bcf\u6b21\u6bd4\u8f83\u4e2d\u95f4\u5143\u7d20&#xff0c;\u6839\u636e\u5927\u5c0f\u5173\u7cfb\u628a\u67e5\u627e\u8303\u56f4\u7f29\u5c0f\u4e00\u534a\u3002<\/p>\n<h4>2. \u5bb9\u6613\u8e29\u7684\u5751<\/h4>\n<li>\n<p>\u6574\u6570\u6ea2\u51fa&#xff1a;\u4e0d\u8981\u5199 (left &#043; right) \/ 2&#xff0c;\u5f53 left \u548c right \u90fd\u63a5\u8fd1 Integer.MAX_VALUE \u65f6\u4f1a\u6ea2\u51fa&#xff0c;\u5fc5\u987b\u5199\u6210 left &#043; (right &#8211; left) \/ 2\u3002<\/p>\n<\/li>\n<li>\n<p>\u8fb9\u754c\u533a\u95f4\u7684\u5199\u6cd5\u8981\u7edf\u4e00&#xff1a;<\/p>\n<ul>\n<li>\n<p><span style=\"background-color:#ffd7b9\">\u95ed\u533a\u95f4 <\/span><span style=\"background-color:#ffd7b9\">[left, right]<\/span><span style=\"background-color:#ffd7b9\">&#xff1a;\u5faa\u73af\u6761\u4ef6 <\/span><span style=\"background-color:#ffd7b9\">left &lt;&#061; right<\/span><span style=\"background-color:#ffd7b9\">&#xff0c;\u66f4\u65b0\u65f6 <\/span><span style=\"background-color:#ffd7b9\">left &#061; mid &#043; 1<\/span><span style=\"background-color:#ffd7b9\"> \u6216 <\/span><span style=\"background-color:#ffd7b9\">right &#061; mid &#8211; 1<\/span><span style=\"background-color:#ffd7b9\">\u3002<\/span><\/p>\n<\/li>\n<li>\n<p><span style=\"background-color:null\">\u5de6\u95ed\u53f3\u5f00 <\/span><span style=\"background-color:null\">[left, right)<\/span><span style=\"background-color:null\">&#xff1a;\u5faa\u73af\u6761\u4ef6 <\/span><span style=\"background-color:null\">left &lt; right<\/span><span style=\"background-color:null\">&#xff0c;\u66f4\u65b0\u65f6 <\/span><span style=\"background-color:null\">left &#061; mid &#043; 1<\/span><span style=\"background-color:null\">\u6216<\/span><span style=\"background-color:null\">right &#061; mid<\/span><span style=\"background-color:null\">&#xff08;<\/span><span style=\"background-color:null\">\u4e0d\u51cf 1<\/span><span style=\"background-color:null\">&#xff09;\u3002<\/span><\/p>\n<\/li>\n<li>\n<p>\u26a0\ufe0f\u4e24\u79cd\u5199\u6cd5\u4e0d\u80fd\u6df7\u7528&#xff0c;\u5426\u5219\u8981\u4e48\u6b7b\u5faa\u73af\u8981\u4e48\u6f0f\u89e3\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6b7b\u5faa\u73af&#xff1a;\u5982\u679c\u5faa\u73af\u91cc\u67d0\u4e2a\u5206\u652f\u5fd8\u8bb0\u8ba9 left \u6216 right \u53d8\u5316&#xff0c;\u4f1a\u5bfc\u81f4\u6b7b\u5faa\u73af\u3002<\/p>\n<\/li>\n<li>\n<p>\u53d8\u4f53\u9898&#xff1a;\u67e5\u627e\u201c\u7b2c\u4e00\u4e2a\u7b49\u4e8e target\u201d\u3001\u201c\u6700\u540e\u4e00\u4e2a\u7b49\u4e8e target\u201d\u3001\u201c\u7b2c\u4e00\u4e2a\u5927\u4e8e\u7b49\u4e8e target\u201d\u7b49\u53d8\u4f53&#xff0c;\u9700\u8981\u5c0f\u5fc3 &lt; \u548c &lt;&#061; \u7684\u53d6\u820d\u3002<\/p>\n<\/li>\n<p>#include &lt;vector&gt;<\/p>\n<p>int binarySearch(const vector&lt;int&gt;&amp; arr, int target) {<br \/>\n    int left &#061; 0, right &#061; arr.size() &#8211; 1;<\/p>\n<p>    \/\/ \u95ed\u533a\u95f4 [left, right]<br \/>\n    while (left &lt;&#061; right) {<br \/>\n        \/\/ \u9632\u6ea2\u51fa\u5199\u6cd5&#xff0c;\u9762\u8bd5\u5fc5\u8003&#xff01;<br \/>\n        int mid &#061; left &#043; (right &#8211; left) \/ 2; <\/p>\n<p>        if (arr[mid] &#061;&#061; target) {<br \/>\n            return mid;<br \/>\n        } else if (arr[mid] &lt; target) {<br \/>\n            left &#061; mid &#043; 1; \/\/ \u66f4\u65b0\u5de6\u8fb9\u754c<br \/>\n        } else {<br \/>\n            right &#061; mid &#8211; 1; \/\/ \u66f4\u65b0\u53f3\u8fb9\u754c<br \/>\n        }<br \/>\n    }<br \/>\n    return -1; \/\/ \u672a\u627e\u5230<br \/>\n}<\/p>\n<h3>\u56db\u3001 DFS \u4e0e BFS&#xff1a;\u56fe\/\u6811\u904d\u5386\u7684\u53cc\u5b50\u661f<\/h3>\n<h4>1. \u533a\u522b\u4e0e\u5b9e\u73b0<\/h4>\n<ul>\n<li>\n<p>DFS&#xff08;\u6df1\u5ea6\u4f18\u5148&#xff09;&#xff1a;\u4e00\u6761\u8def\u8d70\u5230\u9ed1&#xff0c;\u8d70\u4e0d\u901a\u518d\u56de\u6eaf\u3002\u901a\u5e38\u7528\u9012\u5f52\u6216\u6808\u5b9e\u73b0\u3002<\/p>\n<\/li>\n<li>\n<p>BFS&#xff08;\u5e7f\u5ea6\u4f18\u5148&#xff09;&#xff1a;\u4e00\u5c42\u4e00\u5c42\u5411\u5916\u6269\u5c55\u3002\u901a\u5e38\u7528\u961f\u5217\u5b9e\u73b0\u3002<\/p>\n<\/li>\n<\/ul>\n<h4>2. \u5bf9\u6bd4\u8868\u683c<\/h4>\n<table>\n<tr>\u7ef4\u5ea6DFSBFS<\/tr>\n<tbody>\n<tr>\n<td>\u5b9e\u73b0<\/td>\n<td>\u9012\u5f52 \/ \u6808<\/td>\n<td>\u961f\u5217<\/td>\n<\/tr>\n<tr>\n<td>\u7a7a\u95f4\u590d\u6742\u5ea6<\/td>\n<td>O(h)&#xff0c;h \u662f\u9012\u5f52\u6808\u6df1\u5ea6&#xff08;\u6811\u7684\u9ad8\u5ea6&#xff09;<\/td>\n<td>O(w)&#xff0c;w \u662f\u6811\u6700\u5bbd\u4e00\u5c42\u7684\u8282\u70b9\u6570<\/td>\n<\/tr>\n<tr>\n<td>\u80fd\u5426\u6c42\u6700\u77ed\u8def\u5f84<\/td>\n<td>\u4e0d\u80fd\u76f4\u63a5\u6c42<\/td>\n<td>\u53ef\u4ee5&#xff08;\u8fb9\u6743\u76f8\u7b49\u7684\u56fe&#xff0c;BFS \u7b2c\u4e00\u6b21\u5230\u8fbe\u5373\u6700\u77ed\u8def\u5f84&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5178\u578b\u5e94\u7528<\/td>\n<td>\u5168\u6392\u5217\u3001\u5b50\u96c6\u3001\u62d3\u6251\u6392\u5e8f\u3001\u68c0\u6d4b\u73af\u3001\u8fde\u901a\u5206\u91cf\u3001\u56de\u6eaf<\/td>\n<td>\u5c42\u5e8f\u904d\u5386\u3001\u6c42\u6700\u77ed\u8def\u5f84\u3001\u201c\u6700\u5c11\u51e0\u6b65\u201d\u7c7b\u95ee\u9898<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3. \u7ecf\u5178\u9898\u4e3e\u4f8b<\/h4>\n<ul>\n<li>\n<p>\u4e8c\u53c9\u6811\u524d\/\u4e2d\/\u540e\u5e8f\u904d\u5386 \u2192 DFS<\/p>\n<\/li>\n<li>\n<p>\u4e8c\u53c9\u6811\u5c42\u5e8f\u904d\u5386 \u2192 BFS<\/p>\n<\/li>\n<li>\n<p>LeetCode 200 \u5c9b\u5c7f\u6570\u91cf \u2192 DFS\/BFS \u90fd\u884c<\/p>\n<\/li>\n<li>\n<p>LeetCode 994 \u8150\u70c2\u7684\u6a58\u5b50&#xff08;\u6c42\u6700\u77ed\u611f\u67d3\u65f6\u95f4&#xff09; \u2192 BFS<\/p>\n<\/li>\n<li>\n<p>\u56de\u6eaf\u7c7b\u9898\u76ee&#xff08;\u5168\u6392\u5217\u3001N \u7687\u540e\u3001\u5b50\u96c6\u3001\u7ec4\u5408&#xff09; \u2192 DFS<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f4a1; \u4e00\u53e5\u8bdd\u533a\u522b&#xff1a;\u8981\u627e\u6700\u77ed\u8def\u5f84\u3001\u6700\u5c11\u6b65\u6570\u7528 BFS&#xff1b;\u8981\u7a77\u4e3e\u6240\u6709\u65b9\u6848\u6216\u6df1\u6316\u67d0\u6761\u8def\u5f84\u7528 DFS\u3002<\/p>\n<h3>\u4e94\u3001 \u94fe\u8868\u624b\u6495&#xff1a;\u53cd\u8f6c\u94fe\u8868\u4e0e\u73af\u5f62\u94fe\u8868<\/h3>\n<h4>1. \u5982\u4f55\u53cd\u8f6c\u4e00\u4e2a\u94fe\u8868&#xff1f;<\/h4>\n<p>\u8fd9\u662f\u94fe\u8868\u624b\u6495\u9898\u91cc\u6700\u7ecf\u5178\u7684\u4e00\u9053&#xff0c;\u8981\u4f1a\u4e24\u79cd\u89e3\u6cd5\u3002<\/p>\n<ul>\n<li>\n<p>\u89e3\u6cd5\u4e00&#xff1a;\u8fed\u4ee3&#xff08;\u63a8\u8350&#xff0c;O(1) \u7a7a\u95f4&#xff09;<br \/>\n\u7528\u4e09\u4e2a\u6307\u9488 prev\u3001curr\u3001next \u4f9d\u6b21\u8c03\u8f6c\u6bcf\u4e2a\u8282\u70b9\u7684\u6307\u5411\u3002<br \/>\n\u65f6\u95f4\u590d\u6742\u5ea6 O(n)&#xff0c;\u7a7a\u95f4\u590d\u6742\u5ea6 O(1)\u3002<\/p>\n<\/li>\n<\/ul>\n<p>struct ListNode {<br \/>\n    int val;<br \/>\n    ListNode *next;<br \/>\n    ListNode(int x) : val(x), next(nullptr) {}<br \/>\n};<\/p>\n<p>ListNode* reverseList(ListNode* head) {<br \/>\n    ListNode* prev &#061; nullptr;<br \/>\n    ListNode* curr &#061; head;<br \/>\n    while (curr !&#061; nullptr) {<br \/>\n        ListNode* nextTemp &#061; curr-&gt;next; \/\/ \u6682\u5b58\u4e0b\u4e00\u4e2a\u8282\u70b9<br \/>\n        curr-&gt;next &#061; prev;               \/\/ \u53cd\u8f6c\u5f53\u524d\u8282\u70b9\u6307\u9488<br \/>\n        prev &#061; curr;                     \/\/ prev \u524d\u8fdb<br \/>\n        curr &#061; nextTemp;                 \/\/ curr \u524d\u8fdb<br \/>\n    }<br \/>\n    return prev; \/\/ \u6700\u540e prev \u5c31\u662f\u65b0\u7684\u5934\u8282\u70b9<br \/>\n}<\/p>\n<ul>\n<li>\n<p>\u89e3\u6cd5\u4e8c&#xff1a;\u9012\u5f52<br \/>\n\u9012\u5f52\u5230\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u4f5c\u4e3a\u65b0\u5934\u8282\u70b9&#xff0c;\u7136\u540e\u5728\u56de\u6eaf\u7684\u8fc7\u7a0b\u4e2d\u6539\u53d8\u6307\u9488\u6307\u5411\u3002<br \/>\n\u65f6\u95f4\u590d\u6742\u5ea6 O(n)&#xff0c;\u4f46\u9012\u5f52\u6808\u5360\u7528 O(n) \u7a7a\u95f4\u3002<br \/>\n\u26a0\ufe0f\u4e00\u5b9a\u8981\u8003\u8651\u7a7a\u94fe\u8868&#xff08;head &#061;&#061; null&#xff09;\u548c\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\u7684\u8fb9\u754c\u60c5\u51b5&#xff0c;\u4e0a\u9762\u4e24\u79cd\u5199\u6cd5\u90fd\u5df2\u7ecf\u5904\u7406\u4e86\u3002<\/p>\n<\/li>\n<\/ul>\n<p>ListNode* reverseListRecursive(ListNode* head) {<br \/>\n    \/\/ \u8fb9\u754c\u60c5\u51b5&#xff1a;\u7a7a\u94fe\u8868\u6216\u53ea\u6709\u4e00\u4e2a\u8282\u70b9<br \/>\n    if (head &#061;&#061; nullptr || head-&gt;next &#061;&#061; nullptr) return head;<\/p>\n<p>    ListNode* newHead &#061; reverseListRecursive(head-&gt;next);<br \/>\n    head-&gt;next-&gt;next &#061; head; \/\/ \u8ba9\u4e0b\u4e00\u4e2a\u8282\u70b9\u7684 next \u6307\u5411\u5f53\u524d\u8282\u70b9<br \/>\n    head-&gt;next &#061; nullptr;    \/\/ \u5f53\u524d\u8282\u70b9\u7684 next \u8bbe\u4e3a null&#xff0c;\u907f\u514d\u6210\u73af<br \/>\n    return newHead;<br \/>\n}<\/p>\n<h4>2. \u5982\u4f55\u5224\u65ad\u4e00\u4e2a\u94fe\u8868\u662f\u5426\u6709\u73af&#xff1f;\u5982\u4f55\u627e\u5230\u73af\u7684\u5165\u53e3\u8282\u70b9&#xff1f;<\/h4>\n<p>\u8fd9\u662f\u5feb\u6162\u6307\u9488&#xff08;Floyd \u5224\u5708\u7b97\u6cd5&#xff09;\u7684\u7ecf\u5178\u5e94\u7528\u9898&#xff0c;\u4e24\u95ee\u90fd\u6709\u6807\u51c6\u7b54\u6848\u3002<\/p>\n<ul>\n<li>\n<p>\u7b2c\u4e00\u95ee&#xff1a;\u5224\u65ad\u6709\u6ca1\u6709\u73af<br \/>\n\u7528\u4e24\u4e2a\u6307\u9488 slow \u548c fast&#xff0c;slow \u6bcf\u6b21\u8d70 1 \u6b65&#xff0c;fast \u6bcf\u6b21\u8d70 2 \u6b65\u3002<br \/>\n\u5982\u679c fast \u8d70\u5230\u4e86 null&#xff0c;\u8bf4\u660e\u6ca1\u6709\u73af&#xff1b;\u5982\u679c fast \u8ffd\u4e0a\u4e86 slow&#xff08;\u76f8\u9047&#xff09;&#xff0c;\u8bf4\u660e\u6709\u73af\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e8c\u95ee&#xff1a;\u627e\u73af\u7684\u5165\u53e3\u8282\u70b9<br \/>\n\u5173\u952e\u7ed3\u8bba&#xff08;Floyd \u7b97\u6cd5\u7684\u6570\u5b66\u63a8\u5bfc&#xff09;&#xff1a;\u5728 slow \u548c fast \u76f8\u9047\u540e&#xff0c;\u8ba9\u5176\u4e2d\u4e00\u4e2a\u6307\u9488\u56de\u5230\u94fe\u8868\u5934&#xff0c;\u4e24\u4e2a\u6307\u9488\u90fd\u6bcf\u6b21\u8d70\u4e00\u6b65&#xff0c;\u518d\u6b21\u76f8\u9047\u7684\u5730\u65b9\u5c31\u662f\u73af\u7684\u5165\u53e3\u3002<br \/>\n\u6570\u5b66\u539f\u7406&#xff1a;\u8bbe\u5934\u5230\u5165\u53e3\u8ddd\u79bb\u4e3a a&#xff0c;\u5165\u53e3\u5230\u76f8\u9047\u70b9\u4e3a b&#xff0c;\u76f8\u9047\u70b9\u5230\u5165\u53e3&#xff08;\u6cbf\u73af\u8d70&#xff09;\u4e3a c\u3002\u76f8\u9047\u65f6 slow &#061; a &#043; b&#xff0c;fast &#061; a &#043; b &#043; k(b &#043; c)&#xff08;\u591a\u8dd1\u4e86 k \u5708&#xff09;\u3002\u7531 fast &#061; 2 * slow \u63a8\u51fa a &#061; (k &#8211; 1)(b &#043; c) &#043; c&#xff0c;\u542b\u4e49\u5c31\u662f&#xff1a;\u4ece\u5934\u8d70 a \u6b65&#xff0c;\u7b49\u4ef7\u4e8e\u4ece\u76f8\u9047\u70b9\u8d70 c \u6b65\u518d\u8d70\u82e5\u5e72\u6574\u5708&#xff0c;\u4e24\u8005\u4e00\u5b9a\u4f1a\u540c\u65f6\u5230\u8fbe\u5165\u53e3\u3002<\/p>\n<\/li>\n<\/ul>\n<p>ListNode* detectCycle(ListNode* head) {<br \/>\n    ListNode* slow &#061; head;<br \/>\n    ListNode* fast &#061; head;<\/p>\n<p>    while (fast !&#061; nullptr &amp;&amp; fast-&gt;next !&#061; nullptr) {<br \/>\n        slow &#061; slow-&gt;next;<br \/>\n        fast &#061; fast-&gt;next-&gt;next;<\/p>\n<p>        if (slow &#061;&#061; fast) { \/\/ \u76f8\u9047&#xff0c;\u5f00\u59cb\u627e\u5165\u53e3<br \/>\n            ListNode* p &#061; head;<br \/>\n            while (p !&#061; slow) {<br \/>\n                p &#061; p-&gt;next;<br \/>\n                slow &#061; slow-&gt;next;<br \/>\n            }<br \/>\n            return p; \/\/ \u518d\u6b21\u76f8\u9047\u7684\u5730\u65b9\u5c31\u662f\u73af\u7684\u5165\u53e3<br \/>\n        }<br \/>\n    }<br \/>\n    return nullptr; \/\/ \u65e0\u73af<br \/>\n}<\/p>\n<h3>\u00a0\u516d\u3001 \u4e8c\u53c9\u6811\u904d\u5386&#xff1a;\u56db\u79cd\u65b9\u5f0f\u4e00\u7f51\u6253\u5c3d<\/h3>\n<p>\u4e8c\u53c9\u6811\u904d\u5386\u5206\u4e24\u5927\u7c7b&#xff1a;DFS \u4e09\u79cd \u548c BFS \u4e00\u79cd&#xff0c;\u4e00\u5171\u56db\u79cd&#xff0c;\u90fd\u662f\u8d85\u9ad8\u9891\u8003\u70b9\u3002<\/p>\n<h4>1. DFS \u4e09\u79cd&#xff08;\u6839\u636e\u6839\u8282\u70b9\u88ab\u8bbf\u95ee\u7684\u987a\u5e8f\u533a\u5206&#xff09;<\/h4>\n<ul>\n<li>\n<p>\u524d\u5e8f\u904d\u5386&#xff1a;\u6839 \u2192 \u5de6 \u2192 \u53f3<\/p>\n<\/li>\n<li>\n<p>\u4e2d\u5e8f\u904d\u5386&#xff1a;\u5de6 \u2192 \u6839 \u2192 \u53f3&#xff08;\u4e8c\u53c9\u641c\u7d22\u6811\u7684\u4e2d\u5e8f\u904d\u5386\u7ed3\u679c\u662f\u5347\u5e8f\u7684&#xff09;<\/p>\n<\/li>\n<li>\n<p>\u540e\u5e8f\u904d\u5386&#xff1a;\u5de6 \u2192 \u53f3 \u2192 \u6839<\/p>\n<\/li>\n<\/ul>\n<p>\u9012\u5f52\u5b9e\u73b0&#xff08;\u4ee5\u4e2d\u5e8f\u4e3a\u4f8b&#xff09;&#xff1a;\u4ee3\u7801\u975e\u5e38\u7b80\u6d01&#xff0c;\u7262\u8bb0\u201c\u5de6\u3001\u6839\u3001\u53f3\u201d\u7684\u987a\u5e8f\u9012\u5f52\u8c03\u7528\u5373\u53ef\u3002\u8fed\u4ee3\u5b9e\u73b0\u9700\u8981\u663e\u5f0f\u7528\u6808\u3002<\/p>\n<p>#include &lt;stack&gt;<\/p>\n<p>vector&lt;int&gt; inorderTraversal(TreeNode* root) {<br \/>\n    vector&lt;int&gt; result;<br \/>\n   stack&lt;TreeNode*&gt; stk;<br \/>\n    TreeNode* curr &#061; root;<\/p>\n<p>    while (curr !&#061; nullptr || !stk.empty()) {<br \/>\n        \/\/ \u4e00\u8def\u5411\u5de6&#xff0c;\u628a\u5de6\u8282\u70b9\u5168\u90e8\u538b\u6808<br \/>\n        while (curr !&#061; nullptr) {<br \/>\n            stk.push(curr);<br \/>\n            curr &#061; curr-&gt;left;<br \/>\n        }<br \/>\n        \/\/ \u5f39\u51fa\u6808\u9876&#xff08;\u6700\u5de6\u8282\u70b9&#xff09;\u5e76\u8bbf\u95ee<br \/>\n        curr &#061; stk.top();<br \/>\n        stk.pop();<br \/>\n        result.push_back(curr-&gt;val);<br \/>\n        \/\/ \u8f6c\u5411\u53f3\u5b50\u6811<br \/>\n        curr &#061; curr-&gt;right;<br \/>\n    }<br \/>\n    return result;<br \/>\n}<\/p>\n<h4>2. BFS \u4e00\u79cd&#xff1a;\u5c42\u5e8f\u904d\u5386&#xff08;Level Order&#xff09;<\/h4>\n<p>\u7528\u961f\u5217\u5b9e\u73b0&#xff0c;\u4e00\u5c42\u4e00\u5c42\u8bbf\u95ee\u3002<br \/>\n\u6838\u5fc3\u6280\u5de7\u662f\u5728\u6bcf\u4e00\u5c42\u5f00\u59cb\u524d&#xff0c;\u8bb0\u5f55\u5f53\u524d\u961f\u5217\u7684\u5927\u5c0f size&#xff0c;\u7136\u540e\u7528\u4e00\u4e2a\u5faa\u73af\u628a\u5f53\u524d\u5c42\u7684\u8282\u70b9\u5168\u90e8\u5904\u7406\u5b8c&#xff0c;\u5e76\u5c06\u5176\u5b50\u8282\u70b9\u52a0\u5165\u961f\u5217\u3002\u8fd9\u6837\u5c31\u80fd\u5b8c\u7f8e\u5206\u5c42\u8f93\u51fa\u3002<\/p>\n<p>#include &lt;queue&gt;<\/p>\n<p>vector&lt;vector&lt;int&gt;&gt; levelOrder(TreeNode* root) {<br \/>\n    vector&lt;vector&lt;int&gt;&gt; result;<br \/>\n    if (root &#061;&#061; nullptr) return result;<\/p>\n<p>    queue&lt;TreeNode*&gt; q;<br \/>\n    q.push(root);<\/p>\n<p>    while (!q.empty()) {<br \/>\n        int size &#061; q.size(); \/\/ \u8bb0\u5f55\u5f53\u524d\u5c42\u7684\u8282\u70b9\u6570<br \/>\n        vector&lt;int&gt; level;<\/p>\n<p>        for (int i &#061; 0; i &lt; size; &#043;&#043;i) {<br \/>\n            TreeNode* node &#061; q.front();<br \/>\n            q.pop();<br \/>\n            level.push_back(node-&gt;val);<\/p>\n<p>            if (node-&gt;left) q.push(node-&gt;left);<br \/>\n            if (node-&gt;right) q.push(node-&gt;right);<br \/>\n        }<br \/>\n        result.push_back(level);<br \/>\n    }<br \/>\n    return result;<br \/>\n}<\/p>\n<h3>\u00a0\u4e03\u3001\u4ec0\u4e48\u662f\u52a8\u6001\u89c4\u5212&#xff08;DP&#xff09;&#xff1f;<\/h3>\n<p>\u52a8\u6001\u89c4\u5212&#xff08;Dynamic Programming&#xff09;\u662f\u4e00\u79cd\u628a\u5927\u95ee\u9898\u62c6\u89e3\u4e3a\u91cd\u53e0\u5b50\u95ee\u9898\u3001\u901a\u8fc7\u8bb0\u5f55\u5b50\u95ee\u9898\u7684\u89e3\u6765\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u7684\u7b97\u6cd5\u601d\u60f3\u3002\u5b83\u672c\u8d28\u4e0a\u662f\u201c\u806a\u660e\u7684\u66b4\u529b\u679a\u4e3e\u201d\u3002<\/p>\n<p>\u4e00\u4e2a\u95ee\u9898\u662f\u80fd\u5426\u7528DP&#xff0c;\u901a\u5e38\u770b\u4e24\u4e2a\u7279\u5f81&#xff1a;<\/p>\n<li>\n<p>\u6700\u4f18\u5b50\u7ed3\u6784&#xff1a;\u539f\u95ee\u9898\u7684\u6700\u4f18\u89e3\u53ef\u4ee5\u7531\u5b50\u95ee\u9898\u7684\u6700\u4f18\u89e3\u7ec4\u5408\u800c\u6765\u3002<\/p>\n<\/li>\n<li>\n<p>\u91cd\u53e0\u5b50\u95ee\u9898&#xff1a;<span style=\"color:#4da8ee\">\u9012\u5f52\u6c42\u89e3\u65f6\u4f1a\u53cd\u590d\u8ba1\u7b97\u76f8\u540c\u7684\u5b50\u95ee\u9898<\/span>&#xff08;\u8fd9\u6b63\u662fDP\u6bd4\u66b4\u529b\u9012\u5f52\u5feb\u7684\u539f\u56e0&#xff09;\u3002<\/p>\n<\/li>\n<p>&#x1f4a1; \u638c\u63e1DP\u7684\u89e3\u9898\u5957\u8def&#xff08;\u6838\u5fc3\u56db\u6b65\u66f2&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5b9a\u4e49\u72b6\u6001&#xff1a;dp[i] \u6216 dp[i][j] \u5230\u5e95\u8868\u793a\u4ec0\u4e48&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b&#xff1a;dp[i] \u5982\u4f55\u4ece\u4e4b\u524d\u7684\u72b6\u6001\u63a8\u5bfc\u51fa\u6765&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316&#xff1a;\u8fb9\u754c\u72b6\u6001\u5982\u4f55\u8d4b\u503c&#xff1f;<\/p>\n<\/li>\n<li>\n<p>\u904d\u5386\u987a\u5e8f&#xff1a;\u662f\u4ece\u524d\u5f80\u540e\u3001\u4ece\u540e\u5f80\u524d&#xff0c;\u8fd8\u662f\u6309\u67d0\u79cd\u7ef4\u5ea6&#xff1f;<\/p>\n<\/li>\n<\/ul>\n<p>&#x1f525; \u8fdb\u9636\u6280\u5de7&#xff08;\u5fc5\u5907&#xff09;&#xff1a;<br \/>\n\u5148\u60f3\u66b4\u529b\u9012\u5f52 -&gt; \u53d1\u73b0\u91cd\u53e0\u5b50\u95ee\u9898 -&gt; \u7528\u6570\u7ec4\/\u54c8\u5e0c\u8868\u505a\u8bb0\u5fc6\u5316\u641c\u7d22 -&gt; \u6539\u5199\u6210\u81ea\u5e95\u5411\u4e0a\u7684\u8fed\u4ee3DP -&gt; \u6700\u540e\u7528\u6eda\u52a8\u6570\u7ec4\u4f18\u5316\u7a7a\u95f4\u3002\u638c\u63e1\u8fd9\u5957\u6d41\u7a0b&#xff0c;80%\u7684DP\u9898\u90fd\u80fd\u5957&#xff01;<\/p>\n<h5>&#x1f4bb; \u5b9e\u6218&#xff1a;\u6590\u6ce2\u90a3\u5951&#xff08;\u6eda\u52a8\u6570\u7ec4\u7a7a\u95f4\u4f18\u5316&#xff09;<\/h5>\n<p>\u4ee5\u6700\u57fa\u7840\u7684\u722c\u697c\u68af\u4e3a\u4f8b&#xff0c;\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b dp[i] &#061; dp[i-1] &#043; dp[i-2]\u3002\u4e3a\u4e86\u8282\u7701\u7a7a\u95f4&#xff0c;\u6211\u4eec\u4e0d\u7528\u5b58\u6574\u4e2a\u6570\u7ec4&#xff0c;\u53ea\u7528\u4e24\u4e2a\u53d8\u91cf\u3002<\/p>\n<p>int climbStairs(int n) {<br \/>\n    if (n &lt;&#061; 2) return n;<br \/>\n    int prev2 &#061; 1; \/\/ dp[1]<br \/>\n    int prev1 &#061; 2; \/\/ dp[2]<br \/>\n    int current &#061; 0;<br \/>\n    for (int i &#061; 3; i &lt;&#061; n; &#043;&#043;i) {<br \/>\n        current &#061; prev1 &#043; prev2;<br \/>\n        prev2 &#061; prev1;<br \/>\n        prev1 &#061; current;<br \/>\n    }<br \/>\n    return current;<br \/>\n}<\/p>\n<p>\u5178\u578b\u9898\u76ee\u56fe\u8c31&#xff1a; 0-1\u80cc\u5305\u3001\u5b8c\u5168\u80cc\u5305&#xff08;\u96f6\u94b1\u5151\u6362&#xff09;\u3001\u6700\u957f\u516c\u5171\u5b50\u5e8f\u5217&#xff08;LCS&#xff09;\u3001\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217&#xff08;LIS&#xff09;\u3001\u6700\u957f\u56de\u6587\u5b50\u4e32\u3001\u7f16\u8f91\u8ddd\u79bb\u3001\u6253\u5bb6\u52ab\u820d<\/p>\n<h4>\u8d2a\u5fc3\u7b97\u6cd5\u548c\u52a8\u6001\u89c4\u5212\u6709\u4ec0\u4e48\u533a\u522b&#xff1f;<\/h4>\n<p>\u4e24\u8005\u90fd\u7528\u4e8e\u6c42\u6700\u4f18\u89e3\u95ee\u9898&#xff0c;\u4f46\u6838\u5fc3\u533a\u522b\u5728\u4e8e\u505a\u51b3\u7b56\u65f6\u662f\u5426\u56de\u5934\u770b\u3002<\/p>\n<table>\n<tr>\u7ef4\u5ea6\u8d2a\u5fc3\u7b97\u6cd5\u52a8\u6001\u89c4\u5212<\/tr>\n<tbody>\n<tr>\n<td>\u51b3\u7b56\u65b9\u5f0f<\/td>\n<td>\u6bcf\u4e00\u6b65\u90fd\u505a\u5f53\u524d\u770b\u8d77\u6765\u6700\u4f18\u7684\u9009\u62e9<\/td>\n<td>\u679a\u4e3e\u6240\u6709\u53ef\u80fd\u7684\u5b50\u95ee\u9898\u89e3\u518d\u505a\u9009\u62e9<\/td>\n<\/tr>\n<tr>\n<td>\u662f\u5426\u6709\u540e\u6548\u6027<\/td>\n<td>\u5047\u8bbe\u5f53\u524d\u9009\u62e9\u4e0d\u5f71\u54cd\u672a\u6765<\/td>\n<td>\u57fa\u4e8e\u4e4b\u524d\u6240\u6709\u72b6\u6001\u63a8\u5bfc<\/td>\n<\/tr>\n<tr>\n<td>\u6b63\u786e\u6027<\/td>\n<td>\u53ea\u5728\u201c\u8d2a\u5fc3\u9009\u62e9\u6027\u8d28\u201d\u6210\u7acb\u65f6\u624d\u80fd\u5f97\u5230\u6700\u4f18\u89e3<\/td>\n<td>\u53ea\u8981\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\u5b9a\u4e49\u5bf9\u4e86&#xff0c;\u4e00\u5b9a\u80fd\u5f97\u5230\u6700\u4f18\u89e3<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u95f4\u590d\u6742\u5ea6<\/td>\n<td>\u901a\u5e38\u66f4\u5feb&#xff0c;O(n) \u6216 O(n log n)<\/td>\n<td>\u901a\u5e38 O(n\u00b2) \u6216\u66f4\u9ad8<\/td>\n<\/tr>\n<tr>\n<td>\u7a7a\u95f4\u590d\u6742\u5ea6<\/td>\n<td>\u901a\u5e38 O(1)<\/td>\n<td>\u901a\u5e38 O(n) \u6216 O(n\u00b2)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5178\u578b\u8d2a\u5fc3\u9898&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u627e\u96f6\u94b1&#xff08;\u9762\u503c 1\/5\/10\/25&#xff09;&#xff1a;\u6bcf\u6b21\u5c3d\u91cf\u7528\u5927\u9762\u989d\u3002<\/p>\n<\/li>\n<li>\n<p>\u533a\u95f4\u8c03\u5ea6&#xff08;\u6d3b\u52a8\u9009\u62e9&#xff09;&#xff1a;\u6309\u7ed3\u675f\u65f6\u95f4\u6392\u5e8f&#xff0c;\u4f9d\u6b21\u9009\u80fd\u52a0\u5165\u7684\u6d3b\u52a8\u3002<\/p>\n<\/li>\n<li>\n<p>\u970d\u592b\u66fc\u7f16\u7801&#xff1a;\u6bcf\u6b21\u5408\u5e76\u9891\u7387\u6700\u5c0f\u7684\u4e24\u4e2a\u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u8df3\u8dc3\u6e38\u620f&#xff1a;\u6bcf\u4e00\u6b65\u90fd\u8df3\u5230\u201c\u80fd\u5230\u8fbe\u7684\u6700\u8fdc\u4f4d\u7f6e\u201d\u3002<\/p>\n<\/li>\n<\/ul>\n<p><span style=\"color:#fe2c24\">\u8d2a\u5fc3\u662f\u201c\u6bcf\u4e00\u6b65\u90fd\u8d70\u5f53\u524d\u770b\u8d77\u6765\u6700\u597d\u7684\u201d&#xff0c;DP\u662f\u201c\u628a\u6240\u6709\u53ef\u80fd\u6027\u90fd\u7b97\u8fc7\u518d\u9009\u6700\u597d\u7684\u201d\u3002<\/span><span style=\"color:#0d0016\">\u8d2a\u5fc3\u66f4\u5feb\u4f46\u4e0d\u4e00\u5b9a\u6b63\u786e&#xff0c;DP\u4e00\u5b9a\u6b63\u786e\u4f46\u66f4\u6162<\/span><span style=\"color:#0d0016\">\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x1f5c2;\ufe0f \u4e00\u3001 \u54c8\u5e0c\u8868&#xff1a;O(1) \u795e\u8bdd\u7684\u7f14\u9020\u8005\u4e0e\u51b2\u7a81\u89e3\u51b31. \u54c8\u5e0c\u8868\u7684\u539f\u7406\u662f\u4ec0\u4e48&#xff1f;\u54c8\u5e0c\u8868&#xff08;Hash Table&#xff09;\u662f\u4e00\u79cd\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u628a\u952e&#xff08;key&#xff09;\u6620\u5c04\u5230\u6570\u7ec4\u4e0b\u6807&#xff0c;\u4ece\u800c\u5728\u5e73\u5747 O(1) \u65f6\u95f4\u5185\u5b8c\u6210\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\u7684\u6570\u636e\u7ed3\u6784\u3002<br \/>\n\u6838\u5fc3\u539f\u7406\u56db\u6b65\u8d70&#xff1a;\u51c6\u5907\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u4f5c\u4e3a\u201c\u6876\u6570\u7ec4\u201d\u3002\u7528\u54c8\u5e0c\u51fd\u6570 hash(key) \u628a\u952e\u6620\u5c04\u6210\u4e00\u4e2a\u6574\u6570\u3002\u7528\u8fd9\u4e2a\u6574\u6570\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21&amp;#<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55,3520,1813,427,2891],"topic":[],"class_list":["post-112221","post","type-post","status-publish","format-standard","hentry","category-server","tag-c","tag-3520","tag-1813","tag-427","tag-2891"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/112221.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"&#x1f5c2;\ufe0f \u4e00\u3001 \u54c8\u5e0c\u8868&#xff1a;O(1) \u795e\u8bdd\u7684\u7f14\u9020\u8005\u4e0e\u51b2\u7a81\u89e3\u51b31. \u54c8\u5e0c\u8868\u7684\u539f\u7406\u662f\u4ec0\u4e48&#xff1f;\u54c8\u5e0c\u8868&#xff08;Hash Table&#xff09;\u662f\u4e00\u79cd\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u628a\u952e&#xff08;key&#xff09;\u6620\u5c04\u5230\u6570\u7ec4\u4e0b\u6807&#xff0c;\u4ece\u800c\u5728\u5e73\u5747 O(1) \u65f6\u95f4\u5185\u5b8c\u6210\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\u7684\u6570\u636e\u7ed3\u6784\u3002 \u6838\u5fc3\u539f\u7406\u56db\u6b65\u8d70&#xff1a;\u51c6\u5907\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u4f5c\u4e3a\u201c\u6876\u6570\u7ec4\u201d\u3002\u7528\u54c8\u5e0c\u51fd\u6570 hash(key) \u628a\u952e\u6620\u5c04\u6210\u4e00\u4e2a\u6574\u6570\u3002\u7528\u8fd9\u4e2a\u6574\u6570\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21&amp;#\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/112221.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-02T13:48:53+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/112221.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/112221.html\",\"name\":\"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-02T13:48:53+00:00\",\"dateModified\":\"2026-10-02T13:48:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/112221.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/112221.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/112221.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/112221.html","og_locale":"zh_CN","og_type":"article","og_title":"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"&#x1f5c2;\ufe0f \u4e00\u3001 \u54c8\u5e0c\u8868&#xff1a;O(1) \u795e\u8bdd\u7684\u7f14\u9020\u8005\u4e0e\u51b2\u7a81\u89e3\u51b31. \u54c8\u5e0c\u8868\u7684\u539f\u7406\u662f\u4ec0\u4e48&#xff1f;\u54c8\u5e0c\u8868&#xff08;Hash Table&#xff09;\u662f\u4e00\u79cd\u901a\u8fc7\u54c8\u5e0c\u51fd\u6570\u628a\u952e&#xff08;key&#xff09;\u6620\u5c04\u5230\u6570\u7ec4\u4e0b\u6807&#xff0c;\u4ece\u800c\u5728\u5e73\u5747 O(1) \u65f6\u95f4\u5185\u5b8c\u6210\u67e5\u627e\u3001\u63d2\u5165\u3001\u5220\u9664\u7684\u6570\u636e\u7ed3\u6784\u3002 \u6838\u5fc3\u539f\u7406\u56db\u6b65\u8d70&#xff1a;\u51c6\u5907\u4e00\u4e2a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\u4f5c\u4e3a\u201c\u6876\u6570\u7ec4\u201d\u3002\u7528\u54c8\u5e0c\u51fd\u6570 hash(key) \u628a\u952e\u6620\u5c04\u6210\u4e00\u4e2a\u6574\u6570\u3002\u7528\u8fd9\u4e2a\u6574\u6570\u5bf9\u6570\u7ec4\u957f\u5ea6\u53d6\u6a21&amp;#","og_url":"https:\/\/www.wsisp.com\/helps\/112221.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-02T13:48:53+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/112221.html","url":"https:\/\/www.wsisp.com\/helps\/112221.html","name":"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-02T13:48:53+00:00","dateModified":"2026-10-02T13:48:53+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/112221.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/112221.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/112221.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\uff08\u4e09\uff09\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u2014\u2014\u7ecf\u5178\u7b97\u6cd5"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/112221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=112221"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/112221\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=112221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=112221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=112221"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=112221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}