{"id":2140,"date":"2023-10-07T08:42:47","date_gmt":"2023-10-07T00:42:47","guid":{"rendered":"https:\/\/white-night.club\/?p=2140"},"modified":"2023-11-09T11:07:51","modified_gmt":"2023-11-09T03:07:51","slug":"ad27","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/10\/07\/ad27\/","title":{"rendered":"LCR 141.\u00a0\u8bad\u7ec3\u8ba1\u5212 III"},"content":{"rendered":"\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u5934\u8282\u70b9\u4e3a&nbsp;<code>head<\/code>&nbsp;\u7684\u5355\u94fe\u8868\u7528\u4e8e\u8bb0\u5f55\u4e00\u7cfb\u5217\u6838\u5fc3\u808c\u7fa4\u8bad\u7ec3\u7f16\u53f7\uff0c\u8bf7\u5c06\u8be5\u7cfb\u5217\u8bad\u7ec3\u7f16\u53f7&nbsp;<strong>\u5012\u5e8f<\/strong>&nbsp;\u8bb0\u5f55\u4e8e\u94fe\u8868\u5e76\u8fd4\u56de\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>head = [1,2,3,4,5]\n<strong>\u8f93\u51fa\uff1a<\/strong>[5,4,3,2,1]\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>head = [1,2]\n<strong>\u8f93\u51fa\uff1a<\/strong>[2,1]\n<\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>head = []\n<strong>\u8f93\u51fa\uff1a<\/strong>[]\n<\/pre>\n\n\n\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n\n\n\n<ul>\n<li>\u94fe\u8868\u4e2d\u8282\u70b9\u7684\u6570\u76ee\u8303\u56f4\u662f&nbsp;<code>[0, 5000]<\/code><\/li>\n\n\n\n<li><code>-5000 &lt;= Node.val &lt;= 5000<\/code><\/li>\n<\/ul>\n\n\n\n<div style=\"height:60px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote has-luminous-vivid-amber-color has-text-color\">\n<p>\u89e3\u9898\u601d\u8def<\/p>\n<cite><em>\u53c8\u662f\u94fe\u8868\u53cd\u8f6c<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5728\u53cd\u590d\u7ec3\u4e60\u540e\uff0c\u7ec8\u4e8e\u641e\u5b9a\u4e86\u94fe\u8868\u53cd\u8f6c\u7684\u5927\u81f4\u601d\u8def\u3002<\/p>\n\n\n\n<p>\u5148\u662f\u8fed\u4ee3\uff0c\u4e0d\u9700\u8981\u60f3\u7684\u592a\u590d\u6742\u3002\u65b0\u5efa\u4e00\u4e2a\u54d1\u5143\u8282\u70b9pre\uff0c\u540c\u65f6\u5b83\u4e5f\u662f\u6700\u540e\u65b0\u7684\u5934\u8282\u70b9\u3002cur-&gt;next=pre\uff0c\u5c06\u5f53\u524d\u8282\u70b9\u7684next\u6307\u9488\u6307\u5411\u5176\u4e0a\u4e00\u4e2a\u8282\u70b9\u3002\u518d\u8ba9pre=cur\uff0c\u79fb\u52a8pre\u7684\u4f4d\u7f6e\u81f3\u5f53\u524d\u8282\u70b9\u3002\u6700\u540e\u518dcur=tmp\uff0c\u5c06cur\u7684\u4f4d\u7f6e\u79fb\u5230\u4e0b\u4e00\u4e2a\u8282\u70b9\u3002\u5982\u6b64\u8fed\u4ee3\uff0c\u6700\u540e\u8fd4\u56depre\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u5b8c\u6574\u4ee3\u7801\uff08\u8fed\u4ee3\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n *\/\nclass Solution {\npublic:\n    ListNode* trainningPlan(ListNode* head) {\n        ListNode*pre=NULL;\n        ListNode*cur=head;\n        while(cur!=NULL)\n        {\n            ListNode*tmp=cur-&gt;next;\n            cur-&gt;next=pre;\n            pre=cur;\n            cur=tmp;\n        }\n        return pre;\n    }\n};<\/code><\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u662f\u9012\u5f52\u3002\u6bd4\u59821-2-3-4-5\uff0c\u6b64\u65f6head\u57285\u4f4d\u7f6e\u65f6\u5c31\u4f1a\u5f00\u5f80\u56de\u8d70\u30024-5-&gt;next\u6307\u56de\u52304\uff0c\u518d\u5c064-&gt;next\u7f6e\u7a7a\u3002\u7ee7\u7eed\u56de\u9000\uff0c\u518d\u5c063-&gt;4-&gt;next\u6307\u56de\u52303\uff0c\u5c063-&gt;next\u7f6e\u7a7a\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u5b8c\u6574\u4ee3\u7801\uff08\u9012\u5f52\uff09<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n *\/\nclass Solution {\npublic:\n    ListNode* trainningPlan(ListNode* head) {\n        if(head==NULL||head-&gt;next==NULL)\n            return head;\n        ListNode*newHead=trainningPlan(head-&gt;next);\n        head-&gt;next-&gt;next=head;\n        head-&gt;next=NULL;\n        return newHead;\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Leetcode\u9898\u76ee\uff1a\u94fe\u8868\u7684\u9012\u5f52\u548c\u8fed\u4ee3<\/p>\n","protected":false},"author":1,"featured_media":2827,"comment_status":"open","ping_status":"","sticky":false,"template":"base","format":"standard","meta":{"footnotes":""},"categories":[42,25],"tags":[38],"_links":{"self":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2140"}],"collection":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/comments?post=2140"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/2140\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/2827"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=2140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=2140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=2140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}