{"id":74632,"date":"2026-02-10T10:25:27","date_gmt":"2026-02-10T02:25:27","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/74632.html"},"modified":"2026-02-10T10:25:27","modified_gmt":"2026-02-10T02:25:27","slug":"%e5%8a%9b%e6%89%a3%e8%a7%a3%e9%a2%98-%e7%9b%9b%e6%9c%80%e5%a4%9a%e6%b0%b4%e7%9a%84%e5%ae%b9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/74632.html","title":{"rendered":"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668"},"content":{"rendered":"<h2>\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668<\/h2>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 height \u3002\u6709 n \u6761\u5782\u7ebf&#xff0c;\u7b2c i \u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f (i, 0) \u548c (i, height[i]) \u3002<\/p>\n<p>\u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf&#xff0c;\u4f7f\u5f97\u5b83\u4eec\u4e0e x \u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002<\/p>\n<p>\u8fd4\u56de\u5bb9\u5668\u53ef\u4ee5\u50a8\u5b58\u7684\u6700\u5927\u6c34\u91cf\u3002<\/p>\n<p>\u8bf4\u660e&#xff1a;\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002<\/p>\n<p>\u793a\u4f8b 1&#xff1a;<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260210022526-698a97166fe0f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u8f93\u5165&#xff1a;[1,8,6,2,5,4,8,3,7]<br \/>\n\u8f93\u51fa&#xff1a;49<br \/>\n\u89e3\u91ca&#xff1a;\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93\u5165\u6570\u7ec4 [1,8,6,2,5,4,8,3,7]\u3002\u5728\u6b64\u60c5\u51b5\u4e0b&#xff0c;\u5bb9\u5668\u80fd\u591f\u5bb9\u7eb3\u6c34&#xff08;\u8868\u793a\u4e3a\u84dd\u8272\u90e8\u5206&#xff09;\u7684\u6700\u5927\u503c\u4e3a 49\u3002<\/p>\n<p>\u793a\u4f8b 2&#xff1a;<br \/>\n\u8f93\u5165&#xff1a;height &#061; [1,1]<br \/>\n\u8f93\u51fa&#xff1a;1<\/p>\n<p>\u63d0\u793a&#xff1a;<br \/>\nn &#061;&#061; height.length<br \/>\n2 &lt;&#061; n &lt;&#061; 105<br \/>\n0 &lt;&#061; height[i] &lt;&#061; 104<\/p>\n<p>Related Topics<br \/>\n\u8d2a\u5fc3<br \/>\n\u6570\u7ec4<br \/>\n\u53cc\u6307\u9488<\/p>\n<hr \/>\n<h3>\u7b2c\u4e00\u6b21\u89e3\u7b54&#xff08;\u5931\u8d25&#xff0c;\u8d85\u65f6&#xff09;<\/h3>\n<h4>\u89e3\u9898\u601d\u8def<\/h4>\n<p>\u6838\u5fc3\u65b9\u6cd5&#xff1a;\u66b4\u529b\u679a\u4e3e\u6240\u6709\u5782\u7ebf\u7ec4\u5408&#xff0c;\u904d\u5386\u6570\u7ec4\u4e2d\u6bcf\u4e00\u5bf9\u4e0d\u540c\u7684\u5782\u7ebf&#xff0c;\u8ba1\u7b97\u6bcf\u5bf9\u5782\u7ebf\u6784\u6210\u5bb9\u5668\u7684\u76db\u6c34\u91cf&#xff0c;\u6700\u7ec8\u53d6\u6240\u6709\u7ed3\u679c\u7684\u6700\u5927\u503c&#xff0c;\u903b\u8f91\u7b80\u5355\u4f46\u65f6\u95f4\u6548\u7387\u6781\u4f4e\u3002<\/p>\n<p>\u5177\u4f53\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u521d\u59cb\u5316\u6700\u5927\u76db\u6c34\u91cfmax\u4e3a0&#xff0c;\u7528\u4e8e\u8bb0\u5f55\u904d\u5386\u8fc7\u7a0b\u4e2d\u627e\u5230\u7684\u6700\u5927\u6c34\u91cf\u3002<\/li>\n<li>\u5916\u5c42\u5faa\u73af\u904d\u5386\u6570\u7ec4\u7684\u6bcf\u4e2a\u4e0b\u6807i&#xff08;\u4ee3\u8868\u7b2c\u4e00\u6761\u5782\u7ebf\u7684\u4f4d\u7f6e&#xff09;&#xff0c;\u5185\u5c42\u5faa\u73af\u904d\u5386i\u4e4b\u540e\u7684\u6240\u6709\u4e0b\u6807j&#xff08;\u4ee3\u8868\u7b2c\u4e8c\u6761\u5782\u7ebf\u7684\u4f4d\u7f6e&#xff0c;j &gt; i\u907f\u514d\u91cd\u590d\u8ba1\u7b97\u540c\u4e00\u5bf9\u5782\u7ebf&#xff09;\u3002<\/li>\n<li>\u5bf9\u4e8e\u6bcf\u5bf9(i, j)&#xff0c;\u8ba1\u7b97\u5bb9\u5668\u7684\u76db\u6c34\u91cf&#xff1a;\u76db\u6c34\u91cf &#061; \u4e24\u6761\u5782\u7ebf\u7684\u6c34\u5e73\u8ddd\u79bb \u00d7 \u4e24\u6761\u5782\u7ebf\u4e2d\u8f83\u77ee\u7684\u9ad8\u5ea6&#xff0c;\u5373(j &#8211; i) * Math.min(height[i], height[j])\u3002<\/li>\n<li>\u7528\u5f53\u524d\u8ba1\u7b97\u7684\u76db\u6c34\u91cf\u66f4\u65b0max&#xff08;\u53d6max\u548c\u5f53\u524d\u503c\u7684\u8f83\u5927\u8005&#xff09;\u3002<\/li>\n<li>\u4e24\u5c42\u5faa\u73af\u7ed3\u675f\u540e&#xff0c;\u8fd4\u56demax\u4f5c\u4e3a\u6700\u5927\u76db\u6c34\u91cf\u3002<\/li>\n<h4>\u5931\u8d25\u539f\u56e0\u5206\u6790<\/h4>\n<p>\u8be5\u89e3\u6cd5\u8d85\u65f6\u7684\u6838\u5fc3\u539f\u56e0\u662f\u65f6\u95f4\u590d\u6742\u5ea6\u8fc7\u9ad8&#xff0c;\u65e0\u6cd5\u9002\u914d\u9898\u76ee\u6570\u636e\u89c4\u6a21&#xff1a;<\/p>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\u4e3aO(n\u00b2)&#xff1a;\u5916\u5c42\u5faa\u73af\u6267\u884cn\u6b21&#xff0c;\u5185\u5c42\u5faa\u73af\u5e73\u5747\u6267\u884cn\/2\u6b21&#xff0c;\u603b\u8ba1\u7b97\u6b21\u6570\u7ea6\u4e3an\u00b2\/2\u3002\u5bf9\u4e8e\u9898\u76ee\u4e2dn &lt;&#061; 10^5\u7684\u9650\u5236&#xff0c;\u603b\u8ba1\u7b97\u6b21\u6570\u4f1a\u8fbe\u52305\u00d710^9\u7ea7\u522b&#xff0c;\u8fdc\u8d85\u7a0b\u5e8f\u8fd0\u884c\u7684\u65f6\u95f4\u9608\u503c&#xff08;\u901a\u5e38OJ\u5355\u9898\u5141\u8bb8\u7684\u8ba1\u7b97\u6b21\u6570\u7ea610^8&#xff09;&#xff0c;\u5fc5\u7136\u89e6\u53d1\u8d85\u65f6\u3002<\/li>\n<li>\u65e0\u4efb\u4f55\u4f18\u5316\u7b56\u7565&#xff1a;\u66b4\u529b\u679a\u4e3e\u4e86\u6240\u6709\u53ef\u80fd\u7684\u7ec4\u5408&#xff0c;\u672a\u5229\u7528\u201c\u76db\u6c34\u91cf\u7531\u77ee\u8fb9\u51b3\u5b9a\u201d\u7684\u6838\u5fc3\u7279\u6027\u8fdb\u884c\u526a\u679d&#xff0c;\u5b58\u5728\u5927\u91cf\u65e0\u610f\u4e49\u7684\u8ba1\u7b97&#xff0c;\u5b8c\u5168\u65e0\u6cd5\u6ee1\u8db3\u5927\u6570\u636e\u91cf\u7684\u6027\u80fd\u8981\u6c42\u3002<\/li>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">maxArea<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> height<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> max<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span>i<span class=\"token operator\">&lt;<\/span>height<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">;<\/span>i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">for<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> j<span class=\"token operator\">&#061;<\/span>i<span class=\"token operator\">&#043;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>j<span class=\"token operator\">&lt;<\/span>height<span class=\"token punctuation\">.<\/span>length<span class=\"token punctuation\">;<\/span>j<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                max <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Math<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">max<\/span><span class=\"token punctuation\">(<\/span>max<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span>j <span class=\"token operator\">&#8211;<\/span> i<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">*<\/span> <span class=\"token class-name\">Math<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">min<\/span><span class=\"token punctuation\">(<\/span>height<span class=\"token punctuation\">[<\/span>i<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> height<span class=\"token punctuation\">[<\/span>j<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> max<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<hr \/>\n<h3>\u7b2c\u4e8c\u6b21\u89e3\u7b54<\/h3>\n<h4>\u89e3\u9898\u601d\u8def<\/h4>\n<p>\u6838\u5fc3\u65b9\u6cd5&#xff1a;\u53cc\u6307\u9488\u8d2a\u5fc3\u7b56\u7565 &#043; \u5411\u4e2d\u95f4\u6536\u7f29\u903c\u8fd1\u6700\u5927\u503c&#xff0c;\u5229\u7528\u201c\u76db\u6c34\u91cf\u7531\u77ee\u8fb9\u51b3\u5b9a\u201d\u7684\u7279\u6027&#xff0c;\u4ece\u6570\u7ec4\u4e24\u7aef\u5411\u4e2d\u95f4\u79fb\u52a8\u6307\u9488&#xff0c;\u4ec5\u9700\u4e00\u6b21\u904d\u5386\u5373\u53ef\u627e\u5230\u6700\u5927\u76db\u6c34\u91cf&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6\u4f18\u5316\u81f3O(n)\u3002<\/p>\n<p>\u5177\u4f53\u6b65\u9aa4&#xff1a;<\/p>\n<li>\u521d\u59cb\u5316\u53cc\u6307\u9488&#xff1a;\u5de6\u6307\u9488left\u6307\u5411\u6570\u7ec4\u8d77\u59cb\u4f4d\u7f6e&#xff08;\u4e0b\u68070&#xff09;&#xff0c;\u53f3\u6307\u9488right\u6307\u5411\u6570\u7ec4\u672b\u5c3e\u4f4d\u7f6e&#xff08;\u4e0b\u6807height.length-1&#xff09;&#xff1b;\u540c\u65f6\u521d\u59cb\u5316\u6700\u5927\u76db\u6c34\u91cfmax\u4e3a0\u3002<\/li>\n<li>\u5f00\u542f\u5faa\u73af&#xff08;\u7ec8\u6b62\u6761\u4ef6&#xff1a;left &gt;&#061; right&#xff0c;\u5373\u4e24\u6307\u9488\u76f8\u9047\u65f6\u505c\u6b62&#xff09;&#xff1a;<br \/>\na.  \u8ba1\u7b97\u5f53\u524d\u53cc\u6307\u9488\u6784\u6210\u5bb9\u5668\u7684\u76db\u6c34\u91cf&#xff1a;Math.min(height[left], height[right]) * (right &#8211; left)&#xff0c;\u5e76\u7528\u8be5\u503c\u66f4\u65b0max\u3002<br \/>\nb.  \u8d2a\u5fc3\u6536\u7f29\u6307\u9488&#xff1a;\u6bd4\u8f83height[left]\u548cheight[right]\u7684\u5927\u5c0f&#xff0c;\u79fb\u52a8\u8f83\u77ee\u7684\u90a3\u4e2a\u6307\u9488&#xff1a;<br \/>\n&#8211; \u82e5height[left] &lt; height[right]&#xff1a;\u5de6\u6307\u9488left\u53f3\u79fb\u4e00\u4f4d&#xff08;left&#043;&#043;&#xff09;&#xff1b;<br \/>\n&#8211; \u5426\u5219&#xff1a;\u53f3\u6307\u9488right\u5de6\u79fb\u4e00\u4f4d&#xff08;right&#8211;&#xff09;\u3002<\/li>\n<li>\u5faa\u73af\u7ed3\u675f\u540e&#xff0c;max\u5373\u4e3a\u80fd\u5bb9\u7eb3\u7684\u6700\u5927\u6c34\u91cf&#xff0c;\u8fd4\u56de\u8be5\u503c\u3002<\/li>\n<h4>\u6838\u5fc3\u4f18\u5316\u903b\u8f91\u8bf4\u660e<\/h4>\n<p>\u79fb\u52a8\u8f83\u77ee\u6307\u9488\u7684\u5408\u7406\u6027&#xff08;\u8d2a\u5fc3\u7b56\u7565\u7684\u6838\u5fc3&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u5bb9\u5668\u7684\u76db\u6c34\u91cf\u7531\u4e24\u6307\u9488\u7684\u6c34\u5e73\u8ddd\u79bb\u548c\u4e24\u6307\u9488\u4e2d\u8f83\u77ee\u7684\u9ad8\u5ea6\u5171\u540c\u51b3\u5b9a&#xff0c;\u5373\u6c34\u91cf &#061; \u8ddd\u79bb \u00d7 \u77ee\u8fb9\u9ad8\u5ea6\u3002<\/li>\n<li>\u82e5\u79fb\u52a8\u8f83\u9ad8\u7684\u6307\u9488&#xff1a;\u6c34\u5e73\u8ddd\u79bb\u4f1a\u51cf\u5c0f&#xff0c;\u800c\u77ee\u8fb9\u9ad8\u5ea6\u4e0d\u4f1a\u589e\u52a0&#xff08;\u751a\u81f3\u53ef\u80fd\u4e0d\u53d8\/\u51cf\u5c0f&#xff09;&#xff0c;\u76db\u6c34\u91cf\u5fc5\u7136\u4e0d\u4f1a\u589e\u5927&#xff1b;<\/li>\n<li>\u82e5\u79fb\u52a8\u8f83\u77ee\u7684\u6307\u9488&#xff1a;\u6c34\u5e73\u8ddd\u79bb\u51cf\u5c0f&#xff0c;\u4f46\u6709\u53ef\u80fd\u627e\u5230\u66f4\u9ad8\u7684\u8fb9&#xff0c;\u4ece\u800c\u8ba9\u77ee\u8fb9\u9ad8\u5ea6\u63d0\u5347&#xff0c;\u5f25\u8865\u8ddd\u79bb\u51cf\u5c0f\u7684\u635f\u5931&#xff0c;\u6700\u7ec8\u53ef\u80fd\u5f97\u5230\u66f4\u5927\u7684\u76db\u6c34\u91cf\u3002<\/li>\n<li>\u8be5\u7b56\u7565\u786e\u4fdd\u6bcf\u4e00\u6b65\u79fb\u52a8\u90fd\u671d\u7740\u201c\u53ef\u80fd\u589e\u5927\u76db\u6c34\u91cf\u201d\u7684\u65b9\u5411&#xff0c;\u4e14\u4ec5\u9700\u4e00\u6b21\u904d\u5386&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6\u4eceO(n\u00b2)\u964d\u81f3O(n)&#xff0c;\u5b8c\u5168\u9002\u914d10^5\u7ea7\u522b\u7684\u6570\u636e\u89c4\u6a21\u3002<\/li>\n<\/ul>\n<p>\u6267\u884c\u8017\u65f6:5 ms,\u51fb\u8d25\u4e8632.91% \u7684Java\u7528\u6237<br \/>\n\u5185\u5b58\u6d88\u8017:76 MB,\u51fb\u8d25\u4e8619.06% \u7684Java\u7528\u6237<\/p>\n<p><span class=\"token keyword\">public<\/span> <span class=\"token keyword\">int<\/span> <span class=\"token function\">maxArea<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> height<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> left <span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> right <span class=\"token operator\">&#061;<\/span> height<span class=\"token punctuation\">.<\/span>length<span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">int<\/span> max <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span>left<span class=\"token operator\">&lt;<\/span>right<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n            max<span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">Math<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">max<\/span><span class=\"token punctuation\">(<\/span>max<span class=\"token punctuation\">,<\/span><span class=\"token class-name\">Math<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">min<\/span><span class=\"token punctuation\">(<\/span>height<span class=\"token punctuation\">[<\/span>left<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span>height<span class=\"token punctuation\">[<\/span>right<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">(<\/span>right<span class=\"token operator\">&#8211;<\/span>left<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>height<span class=\"token punctuation\">[<\/span>left<span class=\"token punctuation\">]<\/span><span class=\"token operator\">&lt;<\/span>height<span class=\"token punctuation\">[<\/span>right<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n                left<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><span class=\"token keyword\">else<\/span><span class=\"token punctuation\">{<\/span><br \/>\n                right<span class=\"token operator\">&#8212;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> max<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<hr \/>\n<h4>\u603b\u7ed3<\/h4>\n<li>\u7b2c\u4e00\u6b21\u89e3\u7b54\u7684\u66b4\u529b\u679a\u4e3e\u6cd5\u56e0O(n\u00b2)\u7684\u65f6\u95f4\u590d\u6742\u5ea6&#xff0c;\u5728n&#061;10^5\u65f6\u8ba1\u7b97\u91cf\u8d85\u9650&#xff0c;\u76f4\u63a5\u8d85\u65f6&#xff1b;\u5176\u4ec5\u9002\u7528\u4e8e\u6781\u5c0f\u6570\u636e\u91cf&#xff0c;\u65e0\u6cd5\u6ee1\u8db3\u9898\u76ee\u8981\u6c42\u3002<\/li>\n<li>\u7b2c\u4e8c\u6b21\u89e3\u7b54\u7684\u53cc\u6307\u9488\u8d2a\u5fc3\u7b56\u7565\u662f\u672c\u9898\u7684\u6700\u4f18\u89e3&#xff1a;\u5229\u7528\u201c\u76db\u6c34\u91cf\u7531\u77ee\u8fb9\u51b3\u5b9a\u201d\u7684\u7279\u6027&#xff0c;\u901a\u8fc7\u79fb\u52a8\u8f83\u77ee\u6307\u9488\u6536\u7f29\u8303\u56f4&#xff0c;\u4ec5\u9700O(n)\u65f6\u95f4\u590d\u6742\u5ea6\u5b8c\u6210\u904d\u5386&#xff0c;\u9ad8\u6548\u627e\u5230\u6700\u5927\u76db\u6c34\u91cf\u3002<\/li>\n<li>\u672c\u9898\u7684\u6838\u5fc3\u89e3\u9898\u601d\u8def\u662f\u653e\u5f03\u65e0\u610f\u4e49\u7684\u5168\u91cf\u679a\u4e3e&#xff0c;\u901a\u8fc7\u8d2a\u5fc3\u7b56\u7565\u7f29\u5c0f\u641c\u7d22\u8303\u56f4&#xff0c;\u7528\u201c\u7a7a\u95f4\u6362\u65f6\u95f4\u201d\u7684\u53cd\u5411\u601d\u8def&#xff08;\u53cc\u6307\u9488\u4ec5\u5360\u7528\u5e38\u6570\u7a7a\u95f4&#xff09;&#xff0c;\u4ee5\u6700\u4f18\u7684\u65f6\u95f4\u6548\u7387\u89e3\u51b3\u95ee\u9898\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668<br \/>\n\u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 height \u3002\u6709 n \u6761\u5782\u7ebf&#xff0c;\u7b2c i \u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f (i, 0) \u548c (i, height[i]) \u3002<br \/>\n\u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf&#xff0c;\u4f7f\u5f97\u5b83\u4eec\u4e0e x \u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002<br \/>\n\u8fd4\u56de\u5bb9\u5668\u53ef\u4ee5\u50a8\u5b58\u7684\u6700\u5927\u6c34\u91cf\u3002<br \/>\n\u8bf4\u660e&#xff1a;\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002<br \/>\n\u793a\u4f8b 1&#xff1a;\u8f93\u5165&#xff1a;[1,8,6,2,5,4,8,3,7]<br \/>\n\u8f93\u51fa&#xff1a;49<br \/>\n\u89e3\u91ca&#xff1a;\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93<\/p>\n","protected":false},"author":2,"featured_media":74631,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2692,292,427],"topic":[],"class_list":["post-74632","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-leetcode","tag-292","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 - \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\/74632.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 height \u3002\u6709 n \u6761\u5782\u7ebf&#xff0c;\u7b2c i \u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f (i, 0) \u548c (i, height[i]) \u3002 \u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf&#xff0c;\u4f7f\u5f97\u5b83\u4eec\u4e0e x \u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002 \u8fd4\u56de\u5bb9\u5668\u53ef\u4ee5\u50a8\u5b58\u7684\u6700\u5927\u6c34\u91cf\u3002 \u8bf4\u660e&#xff1a;\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002 \u793a\u4f8b 1&#xff1a;\u8f93\u5165&#xff1a;[1,8,6,2,5,4,8,3,7] \u8f93\u51fa&#xff1a;49 \u89e3\u91ca&#xff1a;\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/74632.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-10T02:25:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260210022526-698a97166fe0f.png\" \/>\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=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74632.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/74632.html\",\"name\":\"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-10T02:25:27+00:00\",\"dateModified\":\"2026-02-10T02:25:27+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/74632.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/74632.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74632.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668\"}]},{\"@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":"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 - \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\/74632.html","og_locale":"zh_CN","og_type":"article","og_title":"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 \u7ed9\u5b9a\u4e00\u4e2a\u957f\u5ea6\u4e3a n \u7684\u6574\u6570\u6570\u7ec4 height \u3002\u6709 n \u6761\u5782\u7ebf&#xff0c;\u7b2c i \u6761\u7ebf\u7684\u4e24\u4e2a\u7aef\u70b9\u662f (i, 0) \u548c (i, height[i]) \u3002 \u627e\u51fa\u5176\u4e2d\u7684\u4e24\u6761\u7ebf&#xff0c;\u4f7f\u5f97\u5b83\u4eec\u4e0e x \u8f74\u5171\u540c\u6784\u6210\u7684\u5bb9\u5668\u53ef\u4ee5\u5bb9\u7eb3\u6700\u591a\u7684\u6c34\u3002 \u8fd4\u56de\u5bb9\u5668\u53ef\u4ee5\u50a8\u5b58\u7684\u6700\u5927\u6c34\u91cf\u3002 \u8bf4\u660e&#xff1a;\u4f60\u4e0d\u80fd\u503e\u659c\u5bb9\u5668\u3002 \u793a\u4f8b 1&#xff1a;\u8f93\u5165&#xff1a;[1,8,6,2,5,4,8,3,7] \u8f93\u51fa&#xff1a;49 \u89e3\u91ca&#xff1a;\u56fe\u4e2d\u5782\u76f4\u7ebf\u4ee3\u8868\u8f93","og_url":"https:\/\/www.wsisp.com\/helps\/74632.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-10T02:25:27+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260210022526-698a97166fe0f.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/74632.html","url":"https:\/\/www.wsisp.com\/helps\/74632.html","name":"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-10T02:25:27+00:00","dateModified":"2026-02-10T02:25:27+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/74632.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/74632.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/74632.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u529b\u6263\u89e3\u9898-\u76db\u6700\u591a\u6c34\u7684\u5bb9\u5668"}]},{"@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\/74632","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=74632"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74632\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/74631"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=74632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=74632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=74632"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=74632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}