{"id":1542,"date":"2023-06-27T13:54:14","date_gmt":"2023-06-27T05:54:14","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=1542"},"modified":"2023-06-27T13:54:14","modified_gmt":"2023-06-27T05:54:14","slug":"%e3%80%90%e7%ae%97%e6%b3%95%e9%a2%98%e8%a7%a3%e3%80%918-k-%e4%b8%aa%e4%b8%80%e7%bb%84%e7%bf%bb%e8%bd%ac%e9%93%be%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/%e7%ae%97%e6%b3%95\/%e3%80%90%e7%ae%97%e6%b3%95%e9%a2%98%e8%a7%a3%e3%80%918-k-%e4%b8%aa%e4%b8%80%e7%bb%84%e7%bf%bb%e8%bd%ac%e9%93%be%e8%a1%a8\/","title":{"rendered":"\u3010\u7b97\u6cd5\u9898\u89e3\u30118. K \u4e2a\u4e00\u7ec4\u7ffb\u8f6c\u94fe\u8868"},"content":{"rendered":"<div class='wxsyncmain'>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"outline: 0px;font-weight: bold;font-size: 1.3em;max-width: 100%;letter-spacing: 0.544px;white-space: normal;text-size-adjust: inherit;caret-color: rgb(0, 0, 0);color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;border-bottom: 2px solid rgb(239, 112, 96);visibility: visible;margin-bottom: 0px;margin-top: 0px;box-sizing: border-box !important;overflow-wrap: break-word !important;\"><span style=\"margin-right: 3px;padding: 3px 10px 1px;outline: 0px;max-width: 100%;display: inline-block;background-color: rgb(239, 112, 96);color: rgb(255, 255, 255);border-top-right-radius: 3px;border-top-left-radius: 3px;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;\">\u9898\u76ee<\/span><\/h2>\n<figure data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;outline: 0px;max-width: 100%;letter-spacing: 0.544px;white-space: normal;text-size-adjust: inherit;caret-color: rgb(0, 0, 0);color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 16px;text-align: left;display: flex;flex-direction: column;justify-content: center;align-items: center;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;\"><br  \/><\/figure>\n<blockquote class=\"js_blockquote_wrap\" data-type=\"2\" data-url=\"\" data-author-name=\"\" data-content-utf8-length=\"181\" data-source-title=\"https:\/\/leetcode.cn\/problems\/reverse-nodes-in-k-group\/solutions\/\">\n<section class=\"js_blockquote_digest\">\n<section>\n<p style=\"min-height: 24px;\"><span style=\"color: rgb(38, 38, 38);font-size: 14px;\">\u7ed9\u4f60\u94fe\u8868\u7684\u5934\u8282\u70b9 <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">head<\/span><\/code><span style=\"color: rgb(38, 38, 38);font-size: 14px;\"> \uff0c\u6bcf <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">k<\/span><\/code><span style=\"color: rgb(38, 38, 38);font-size: 14px;\">\u4e2a\u8282\u70b9\u4e00\u7ec4\u8fdb\u884c\u7ffb\u8f6c\uff0c\u8bf7\u4f60\u8fd4\u56de\u4fee\u6539\u540e\u7684\u94fe\u8868\u3002<\/span><\/p>\n<p style=\"min-height: 24px;\"><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">k<\/span><\/code><span style=\"color: rgb(38, 38, 38);font-size: 14px;\"> \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u5b83\u7684\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u94fe\u8868\u7684\u957f\u5ea6\u3002\u5982\u679c\u8282\u70b9\u603b\u6570\u4e0d\u662f <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">k<\/span><\/code><span style=\"color: rgb(38, 38, 38);font-size: 14px;\">\u7684\u6574\u6570\u500d\uff0c\u90a3\u4e48\u8bf7\u5c06\u6700\u540e\u5269\u4f59\u7684\u8282\u70b9\u4fdd\u6301\u539f\u6709\u987a\u5e8f\u3002<\/span><\/p>\n<p style=\"min-height: 24px;\"><span style=\"color: rgb(38, 38, 38);font-size: 14px;\">\u4f60\u4e0d\u80fd\u53ea\u662f\u5355\u7eaf\u7684\u6539\u53d8\u8282\u70b9\u5185\u90e8\u7684\u503c\uff0c\u800c\u662f\u9700\u8981\u5b9e\u9645\u8fdb\u884c\u8282\u70b9\u4ea4\u6362\u3002<\/span><\/p>\n<p style=\"min-height: 24px;\"><strong><span style=\"color: rgb(38, 38, 38);font-size: 14px;\">\u63d0\u793a\uff1a<\/span><\/strong><\/p>\n<ul class=\"list-paddingleft-1\" style=\"padding-left: 23px;\">\n<li>\n<p><span style=\"color: rgb(38, 38, 38);font-size: 14px;\">\u94fe\u8868\u4e2d\u7684\u8282\u70b9\u6570\u76ee\u4e3a <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">n<\/span><\/code><\/p>\n<\/li>\n<li>\n<p><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">1 &lt;= k &lt;= n &lt;= 5000<\/span><\/code><\/p>\n<\/li>\n<li>\n<p><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"color: rgba(38, 38, 38, 0.75);font-size: 14px;\">0 &lt;= Node.val &lt;= 1000<\/span><\/code><\/p>\n<\/li>\n<\/ul>\n<\/section>\n<\/section>\n<section class=\"blockquote_info js_blockquote_source\" data-json=\"%7B%22type%22%3A%22out%22%2C%22source%22%3A%22url%22%2C%22digest%22%3A%22%22%2C%22digestLen%22%3A181%2C%22text%22%3A%22%E7%BB%99%E4%BD%A0%E9%93%BE%E8%A1%A8%E7%9A%84%E5%A4%B4%E8%8A%82%E7%82%B9%20head%20%EF%BC%8C%E6%AF%8F%20k%20%E4%B8%AA%E8%8A%82%E7%82%B9%E4%B8%80%E7%BB%84%E8%BF%9B%E8%A1%8C%E7%BF%BB%E8%BD%AC%EF%BC%8C%E8%AF%B7%E4%BD%A0%E8%BF%94%E5%9B%9E%E4%BF%AE%E6%94%B9%E5%90%8E%E7%9A%84%E9%93%BE%E8%A1%A8%E3%80%82k%20%E6%98%AF%E4%B8%80%E4%B8%AA%E6%AD%A3%E6%95%B4%E6%95%B0%EF%BC%8C%E5%AE%83%E7%9A%84%E5%80%BC%E5%B0%8F%E4%BA%8E%E6%88%96%E7%AD%89%E4%BA%8E%E9%93%BE%E8%A1%A8%E7%9A%84%E9%95%BF%E5%BA%A6%E3%80%82%E5%A6%82%E6%9E%9C%E8%8A%82%E7%82%B9%E6%80%BB%E6%95%B0%E4%B8%8D%E6%98%AF%20k%20%E7%9A%84%E6%95%B4%E6%95%B0%E5%80%8D%EF%BC%8C%E9%82%A3%E4%B9%88%E8%AF%B7%E5%B0%86%E6%9C%80%E5%90%8E%E5%89%A9%E4%BD%99%E7%9A%84%E8%8A%82%E7%82%B9%E4%BF%9D%E6%8C%81%E5%8E%9F%E6%9C%89%E9%A1%BA%E5%BA%8F%E3%80%82%E4%BD%A0%E4%B8%8D%E8%83%BD%E5%8F%AA%E6%98%AF%E5%8D%95%E7%BA%AF%E7%9A%84%E6%94%B9%E5%8F%98%E8%8A%82%E7%82%B9%E5%86%85%E9%83%A8%E7%9A%84%E5%80%BC%EF%BC%8C%E8%80%8C%E6%98%AF%E9%9C%80%E8%A6%81%E5%AE%9E%E9%99%85%E8%BF%9B%E8%A1%8C%E8%8A%82%E7%82%B9%E4%BA%A4%E6%8D%A2%E3%80%82%E6%8F%90%E7%A4%BA%EF%BC%9A%E9%93%BE%E8%A1%A8%E4%B8%AD%E7%9A%84%E8%8A%82%E7%82%B9%E6%95%B0%E7%9B%AE%E4%B8%BA%20n1%20%3C%3D%20k%20%3C%3D%20n%20%3C%3D%2050000%20%3C%3D%20Node.val%20%3C%3D%201000%22%2C%22article%22%3A%7B%7D%2C%22hasReportOverSize%22%3Afalse%2C%22editorReportData%22%3A%5B%7B%22id%22%3A%22122333%22%2C%22key%22%3A%2276%22%2C%22len%22%3A1%7D%5D%2C%22from%22%3A%22https%3A%2F%2Fleetcode.cn%2Fproblems%2Freverse-nodes-in-k-group%2Fsolutions%2F%22%7D\"><span class=\"blockquote_other\">https:\/\/leetcode.cn\/problems\/reverse-nodes-in-k-group\/solutions\/<\/span><\/section>\n<\/blockquote>\n<section style=\"margin-bottom: 0px;\"><br  \/><\/section>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"outline: 0px;font-weight: bold;font-size: 1.3em;max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-size-adjust: inherit;caret-color: rgb(0, 0, 0);color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;border-bottom: 2px solid rgb(239, 112, 96);visibility: visible;margin-top: 0px;box-sizing: border-box !important;overflow-wrap: break-word !important;\"><span style=\"margin-right: 3px;padding: 3px 10px 1px;outline: 0px;max-width: 100%;display: inline-block;background-color: rgb(239, 112, 96);color: rgb(255, 255, 255);border-top-right-radius: 3px;border-top-left-radius: 3px;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;\">\u89e3\u9898\u601d\u8def<\/span><\/h2>\n<section style=\"outline: 0px;max-width: 100%;color: rgb(34, 34, 34);font-family: system-ui, -apple-system, &quot;system-ui&quot;, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);visibility: visible;margin-bottom: 0px;margin-top: 0px;box-sizing: border-box !important;overflow-wrap: break-word !important;\"><br  \/><\/section>\n<section style=\"min-height: 24px;margin-bottom: 0px;\"><span style=\"font-size: 15px;color: rgb(79, 79, 79);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun;font-variant-ligatures: no-common-ligatures;font-weight: 600;letter-spacing: 0.544px;text-align: start;background-color: rgb(255, 255, 255);\">\u4e3b\u4f53\u6d41\u7a0b\u5206\u4ee5\u4e0b\u4e09\u6b65\uff1a<\/span><\/section>\n<section style=\"margin-bottom: 0px;\"><span style=\"font-size: 15px;\">1. \u5c06\u94fe\u8868\u4e2d\u7684\u8282\u70b9\uff0c\u4ece\u5934\u5f00\u59cb\u6bcf <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">k<\/span><\/code><span style=\"font-size: 15px;\"> \u4e2a\u5206\u4e3a\u4e00\u7ec4\u3002<\/span><\/section>\n<section style=\"margin-bottom: 0px;\"><span style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 15px;\">2. \u5c06\u6bcf\u7ec4 <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">k<\/span><\/code><span style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 15px;\"> \u4e2a\u8282\u70b9\u8fdb\u884c\u53cd\u8f6c\u3002<\/span><\/section>\n<section style=\"margin-bottom: 0px;\"><span style=\"font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 15px;\">3. \u5c06\u53cd\u8f6c\u540e\u7684\u6bcf\u4e2a\u7ec4\u8fde\u63a5\u8d77\u6765\u3002<\/span><\/section>\n<section style=\"margin-bottom: 0px;\"><br  \/><\/section>\n<p style=\"margin-bottom: 0px;margin-top: 0px;\"><span style=\"font-size: 15px;font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;\">\u4e0b\u9762\u5c31\u4e3b\u4f53\u6d41\u7a0b\u4e2d\u7684\u6bcf\u4e00\u6b65\u62c6\u5f00\u6765\u5206\u6790\uff1a<br  \/><\/span><\/p>\n<p style=\"margin-bottom: 0px;margin-top: 0px;\"><span style=\"font-size: 15px;\"><span style=\"color: rgb(79, 79, 79);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, SimHei, Arial, SimSun;font-variant-ligatures: no-common-ligatures;font-weight: 600;letter-spacing: 0.544px;text-align: start;background-color: rgb(255, 255, 255);\">1. \u5206\u7ec4\uff1a<\/span>\u4ece\u8d77\u59cb\u70b9\u5f80\u540e\u8d70 <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">k-1<\/span><\/code><span style=\"font-size: 15px;\">\u6b65\u4e3a\u4e00\u7ec4\uff0c\u8fd4\u56de\u6700\u540e\u4e00\u4e2a\u8282\u70b9 <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">end<\/span><\/code><span style=\"font-size: 15px;\">\u3002\u4e0d\u591f <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">k-1<\/span><\/code><span style=\"font-size: 15px;\"> \u6b65\u8fd4\u56de <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">null<\/span><\/code><span style=\"font-size: 15px;\">\uff08\u4e0d\u8fdb\u884c\u7b2c\u4e8c\u6b65\u53cd\u8f6c\uff0c\u76f4\u63a5\u548c\u524d\u9762\u7684\u7ec4\u8fde\u63a5\u8d77\u6765\uff09\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\" data-lang=\"kotlin\"><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">\/\/ \u5faa\u73af\u904d\u5386\u94fe\u8868\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__keyword\">while<\/span>(head != <span class=\"code-snippet__literal\">null<\/span>){<\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__comment\">\/\/ \u83b7\u53d6\u5206\u7ec4\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    ListNode end = getEnd(head, k);<\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__keyword\">if<\/span>(end == <span class=\"code-snippet__literal\">null<\/span>){<\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__comment\">\/\/ \u4e0d\u591f k \u4e2a\u8282\u70b9\u76f4\u63a5\u8fd4\u56de\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">break<\/span>;<\/span><\/code><code><span class=\"code-snippet_outer\">    }<\/span><\/code><code><span class=\"code-snippet_outer\">    <\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__comment\">\/\/ \u521a\u597d\u53d6\u5f97 k \u4e2a\u8282\u70b9\uff0c[head, end]\u3002\u8fd9\u91cc\u5c31\u53ef\u4ee5\u51c6\u5907\u8fdb\u5165\u7b2c\u4e8c\u6b65\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__comment\">\/\/ \u4e0b\u4e00\u7ec4\u7684\u5f00\u5934 <\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    ListNode nextGroupHead = end.next;<\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__comment\">\/\/ head \u6307\u5411\u4e0b\u4e00\u7ec4\u7684\u5f00\u5934\uff0c\u67e5\u627e\u4e0b\u4e00\u7ec4\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    head = nextGroupHead;         <\/span><\/code><code><span class=\"code-snippet_outer\">}<\/span><\/code><\/pre>\n<\/section>\n<section style=\"margin-bottom: 0px;\"><span style=\"font-size: 15px;\"><strong>2. \u7ec4\u5185\u53cd\u8f6c\uff1a<\/strong>\u89e3\u6cd5\u53c2\u8003<a target=\"_blank\" href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzU1OTYwMjk1OQ==&amp;mid=2247483756&amp;idx=1&amp;sn=3dada3b6769bb3b48ff4f40d3887896b&amp;chksm=fc158d0ccb62041a0db183f394123bcabc4431e44bccbed54aa28b718e05f39c37446d89d76f&amp;scene=21#wechat_redirect\" textvalue=\"\u3010\u7b97\u6cd5\u9898\u89e3\u30117. \u53cd\u8f6c\u94fe\u8868\" linktype=\"text\" imgurl=\"\" imgdata=\"null\" data-itemshowtype=\"0\" tab=\"innerlink\" data-linktype=\"2\" rel=\"noopener\" rel=\"nofollow\" >\u3010\u7b97\u6cd5\u9898\u89e3\u30117. \u53cd\u8f6c\u94fe\u8868<\/a>\u3002<\/span><\/section>\n<p><span style=\"font-size: 15px;\"><strong>3. \u8fde\u63a5\u53cd\u8f6c\u540e\u7684\u6bcf\u4e00\u7ec4\uff1a<\/strong>\u6bcf\u7ec4\u53cd\u8f6c\u540e\u7684\u8282\u70b9 <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">end<\/span><\/code><span style=\"font-size: 15px;\"> \u53d8\u4e3a\u5f00\u5934\uff0c<\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">head<\/span><\/code><span style=\"font-size: 15px;\"> \u53d8\u4e3a\u7ed3\u5c3e\u3002\u8981\u60f3\u8fde\u63a5\u6bcf\u4e00\u7ec4\uff0c\u9700\u8981\u5c06\u4e0a\u4e00\u7ec4\u7684<\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">head<\/span><\/code><span style=\"font-size: 15px;\"> \u6307\u5411\u4e0b\u4e00\u7ec4\u53cd\u8f6c\u540e\u7684\u5f00\u5934\uff08\u5373<\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">\u4e0b\u4e00\u7ec4\u7684end<\/span><\/code><span style=\"font-size: 15px;\">\uff09\uff0c\u8fd9\u91cc\u9700\u8981\u8003\u8651\u4e34\u754c\u503c\uff0c\u56e0\u4e3a\u7b2c\u4e00\u7ec4\u6ca1\u6709\u4e0a\u4e00\u7ec4\uff0c\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5f00\u4e00\u4e2a\u4fdd\u62a4\u8282\u70b9<\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">protect<\/span><\/code><span style=\"font-size: 15px;\">\u3002<\/span><\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"rich_pages wxw-img lazyload\" data-galleryid=\"\" data-ratio=\"0.5625\"  data-type=\"gif\" data-w=\"720\" style=\"\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043604482.gif\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\"><noscript><img decoding=\"async\" class=\"rich_pages wxw-img\" data-galleryid=\"\" data-ratio=\"0.5625\"  data-type=\"gif\" data-w=\"720\" style=\"\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043604482.gif\"><\/noscript><\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 30px;font-weight: bold;font-size: 1.3em;white-space: normal;outline: 0px;max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);text-size-adjust: inherit;caret-color: rgb(0, 0, 0);color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;border-bottom: 2px solid rgb(239, 112, 96);visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;\"><span style=\"margin-right: 3px;padding: 3px 10px 1px;outline: 0px;max-width: 100%;display: inline-block;background-color: rgb(239, 112, 96);color: rgb(255, 255, 255);border-top-right-radius: 3px;border-top-left-radius: 3px;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;\">\u5b8c\u6574\u4ee3\u7801<\/span><\/h2>\n<section style=\"margin-bottom: 0px;\"><br  \/><\/section>\n<section class=\"code-snippet__fix code-snippet__js\">\n<ul class=\"code-snippet__line-index code-snippet__js\">\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<li><\/li>\n<\/ul>\n<pre class=\"code-snippet__js\" data-lang=\"cs\"><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">\/**<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> * Definition for singly-linked list.<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> * public class ListNode {<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> *     int val;<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> *     ListNode next;<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> *     ListNode() {}<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> *     ListNode(int val) { this.val = val; }<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> * }<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\"> *\/<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__keyword\">class<\/span> <span class=\"code-snippet__title\">Solution<\/span> {<\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__function\"><span class=\"code-snippet__keyword\">public<\/span> ListNode <span class=\"code-snippet__title\">reverseKGroup<\/span>(<span class=\"code-snippet__params\">ListNode head, <span class=\"code-snippet__keyword\">int<\/span> k<\/span>)<\/span> {<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">        ListNode protectNode = <span class=\"code-snippet__keyword\">new<\/span> ListNode(<span class=\"code-snippet__number\">0<\/span>);<\/span><\/code><code><span class=\"code-snippet_outer\">        ListNode lastGroupTail = protectNode;<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__comment\">\/\/ 1. k\u4e2a1\u7ec4\uff0c\u8fdb\u884c\u5206\u7ec4<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">while<\/span>(head != <span class=\"code-snippet__literal\">null<\/span>){<\/span><\/code><code><span class=\"code-snippet_outer\">            ListNode end = getEnd(head, k);<\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__keyword\">if<\/span>(end == <span class=\"code-snippet__literal\">null<\/span>){<\/span><\/code><code><span class=\"code-snippet_outer\">                <span class=\"code-snippet__comment\">\/\/ \u4e0d\u591f k \u4e2a\u5143\u7d20\u76f4\u63a5\u8fd4\u56de, \u8df3\u51fa\u5faa\u73af\uff0c\u65e0\u9700\u53cd\u8f6c\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">                <span class=\"code-snippet__keyword\">break<\/span>;<\/span><\/code><code><span class=\"code-snippet_outer\">            }<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__comment\">\/\/ \u4e0b\u4e00\u7ec4\u7684\u5f00\u5934 <\/span><\/span><\/code><code><span class=\"code-snippet_outer\">            ListNode nextGroupHead = end.next;<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__comment\">\/\/ 2. \u6bcf\u7ec4\u8fdb\u884c\u5185\u90e8\u53cd\u8f6c\u94fe\u8868<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__comment\">\/\/ [head, end] \u4e3a\u4e00\u7ec4, \u8fdb\u884c\u53cd\u8f6c\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__keyword\">this<\/span>.reverse(head, end);<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__comment\">\/\/ 3. \u5c06\u53cd\u8f6c\u540e\u7684\u5217\u8868\u8fde\u8d77\u6765<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">            lastGroupTail.next = end;<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">            head.next = nextGroupHead;<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">            lastGroupTail = head;<\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__comment\">\/\/ head \u6307\u5411\u4e0b\u4e00\u7ec4\u7684\u5f00\u5934\uff0c\u67e5\u627e\u4e0b\u4e00\u7ec4\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">            head = nextGroupHead;<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">        }      <\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">return<\/span> protectNode.next; <\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">    }<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__function\"><span class=\"code-snippet__keyword\">private<\/span> ListNode <span class=\"code-snippet__title\">reverse<\/span>(<span class=\"code-snippet__params\">ListNode head, ListNode end<\/span>)<\/span>{<\/span><\/code><code><span class=\"code-snippet_outer\">        ListNode pre = <span class=\"code-snippet__literal\">null<\/span>;<\/span><\/code><code><span class=\"code-snippet_outer\">        ListNode stop = end.next;<\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__comment\">\/\/ \u8fd9\u4e0d\u80fd\u4f7f\u7528 wile(head != end.next), \u56e0\u4e3a\u5faa\u73af\u5185\u90e8\u4f1a\u5c06end.next\u53cd\u8f6c\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">while<\/span>(head != stop){<\/span><\/code><code><span class=\"code-snippet_outer\">            ListNode nextNode = head.next;<\/span><\/code><code><span class=\"code-snippet_outer\">            head.next = pre;<\/span><\/code><code><span class=\"code-snippet_outer\">            pre = head;<\/span><\/code><code><span class=\"code-snippet_outer\">            head = nextNode;<\/span><\/code><code><span class=\"code-snippet_outer\">        }<\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">return<\/span> pre;<\/span><\/code><code><span class=\"code-snippet_outer\">    }<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__comment\">\/**<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">    * \u6839\u636e head \u5411\u540e\u627e\u7b2c k - 1 \u4e2a\u5143\u7d20\u4e3a end, \u5982\u679c\u4e0d\u591f k \u4e2a\u5143\u7d20\u76f4\u63a5\u8fd4\u56denull, \u4e0d\u7528\u53cd\u8f6c\u3002<\/span><\/span><\/code><code><span class=\"code-snippet_outer\"><span class=\"code-snippet__comment\">    *\/<\/span><\/span><\/code><code><span class=\"code-snippet_outer\">    <span class=\"code-snippet__function\"><span class=\"code-snippet__keyword\">private<\/span> ListNode <span class=\"code-snippet__title\">getEnd<\/span>(<span class=\"code-snippet__params\">ListNode head, <span class=\"code-snippet__keyword\">int<\/span> k<\/span>)<\/span>{<\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">while<\/span>(head != <span class=\"code-snippet__literal\">null<\/span>){<\/span><\/code><code><span class=\"code-snippet_outer\">            k--;<\/span><\/code><code><span class=\"code-snippet_outer\">            <span class=\"code-snippet__keyword\">if<\/span>(k == <span class=\"code-snippet__number\">0<\/span>){<\/span><\/code><code><span class=\"code-snippet_outer\">                <span class=\"code-snippet__keyword\">return<\/span> head;<\/span><\/code><code><span class=\"code-snippet_outer\">            }<\/span><\/code><code><span class=\"code-snippet_outer\">            head = head.next;<\/span><\/code><code><span class=\"code-snippet_outer\">        }<\/span><\/code><code><span class=\"code-snippet_outer\">        <span class=\"code-snippet__keyword\">return<\/span> <span class=\"code-snippet__literal\">null<\/span>;<\/span><\/code><code><span class=\"code-snippet_outer\">    }<\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\"><br  \/><\/span><\/code><code><span class=\"code-snippet_outer\">}<\/span><\/code><\/pre>\n<\/section>\n<section style=\"margin-bottom: 0px;\"><br  \/><\/section>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 1.3em;outline: 0px;max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-size-adjust: inherit;caret-color: rgb(0, 0, 0);color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;border-bottom: 2px solid rgb(239, 112, 96);visibility: visible;margin-top: 0px;box-sizing: border-box !important;overflow-wrap: break-word !important;\"><span style=\"margin-right: 3px;padding: 3px 10px 1px;outline: 0px;max-width: 100%;display: inline-block;background-color: rgb(239, 112, 96);color: rgb(255, 255, 255);border-top-right-radius: 3px;border-top-left-radius: 3px;visibility: visible;box-sizing: border-box !important;overflow-wrap: break-word !important;\">\u590d\u6742\u5ea6\u5206\u6790<\/span><\/h2>\n<p style=\"margin-bottom: 0px;margin-top: 0px;\"><br  \/><\/p>\n<p style=\"min-height: 24px;margin-bottom: 0px;margin-top: 0px;\"><span style=\"font-size: 15px;\"><strong>\u65f6\u95f4\u590d\u6742\u5ea6O(n)\uff1a<\/strong><\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">getEnd<\/span><\/code><span style=\"font-size: 15px;\"> \u6bcf\u6b21\u5faa\u73afk\u6b21\uff0c\u6700\u540e\u4e00\u6b21 &nbsp;<\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">&lt;= k<\/span><\/code><span style=\"font-size: 15px;\">\uff0c\u4f46\u662f\u603b\u4f53\u52a0\u8d77\u6765\u662f <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">n<\/span><\/code><span style=\"font-size: 15px;\">\u3002<\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">reverse<\/span><\/code><span style=\"font-size: 15px;\"> \u6bcf\u6b21\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4e5f\u662f <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">k<\/span><\/code><span style=\"font-size: 15px;\">\uff0c\u52a0\u4ee5\u6765 <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">&lt;= n<\/span><\/code><span style=\"font-size: 15px;\">\uff0c\u56e0\u4e3a\u6700\u540e\u4e00\u7ec4\u53ef\u80fd\u9700\u8981\u53cd\u8f6c\u3002\u603b\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u7ea6\u4e3a <\/span><code style=\"font-family: SFMono-Regular, Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;background-color: rgba(0, 0, 0, 0.06);border-width: 1px;border-style: solid;border-color: rgba(0, 0, 0, 0.08);border-radius: 2px;padding-right: 2px;padding-left: 2px;\"><span style=\"font-size: 15px;\">2n<\/span><\/code><span style=\"font-size: 15px;\">, \u5ffd\u7565\u5e38\u6570\u540e\u4e3a O(n)\uff1b<\/span><\/p>\n<p style=\"min-height: 24px;margin-bottom: 0px;margin-top: 0px;\"><span style=\"font-size: 15px;\"><br  \/><\/span><\/p>\n<p style=\"min-height: 24px;margin-bottom: 0px;margin-top: 0px;\"><span style=\"font-size: 15px;\"><strong>\u7a7a\u95f4\u590d\u6742\u5ea6O(1)<\/strong><\/span><span style=\"font-size: 15px;\">\uff1a\u989d\u5916\u5f00\u542f\u7684\u53d8\u91cf\u90fd\u662f\u5e38\u6570\u7ea7\u7684\uff0c\u6240\u4ee5\u7a7a\u95f4\u590d\u6742\u5ea6\u4e3aO(1)\u3002<\/span><\/p>\n<p><br  \/><\/p>\n<p style=\"display: none;\"><mp-style-type data-value=\"3\"><\/mp-style-type><\/p>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 i\u4f59\u6570              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee \u7ed9\u4f60\u94fe\u8868\u7684\u5934\u8282\u70b9 head \uff0c\u6bcf k\u4e2a\u8282\u70b9\u4e00\u7ec4\u8fdb\u884c\u7ffb\u8f6c\uff0c\u8bf7\u4f60\u8fd4\u56de\u4fee\u6539\u540e\u7684\u94fe\u8868\u3002 k \u662f\u4e00\u4e2a\u6b63\u6574\u6570\uff0c\u5b83\u7684\u503c\u5c0f\u4e8e\u6216\u7b49\u4e8e\u94fe\u8868\u7684\u957f\u5ea6 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":1540,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[22],"tags":[],"class_list":["post-1542","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-22"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043603366-150x150.jpeg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043604482.gif","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043603366-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043603366.jpeg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043604482.gif","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043603366-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043603366.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043603366.jpeg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043604482.gif","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528043604482.gif","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"\u7b97\u6cd5","post_date":"2023-06-27","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":267,"next_post_id":2484,"next_post_title":"Java\u4e2d\u5c06 int[] \u6570\u7ec4 \u8f6c\u6362\u4e3a List\uff08ArrayList\uff09","previous_post_id":1489,"previous_post_title":"\u3010\u7b97\u6cd5\u9898\u89e3\u301114. \u6709\u6548\u7684\u62ec\u53f7","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1542"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/1542\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/1540"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}