{"id":1136,"date":"2023-04-29T17:43:26","date_gmt":"2023-04-29T09:43:26","guid":{"rendered":"https:\/\/white-night.club\/?p=1136"},"modified":"2023-11-09T11:07:55","modified_gmt":"2023-11-09T03:07:55","slug":"ad7","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/04\/29\/ad7\/","title":{"rendered":"206.\u00a0\u53cd\u8f6c\u94fe\u8868"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u5355\u94fe\u8868\u7684\u5934\u8282\u70b9&nbsp;<code>head<\/code>&nbsp;\uff0c\u8bf7\u4f60\u53cd\u8f6c\u94fe\u8868\uff0c\u5e76\u8fd4\u56de\u53cd\u8f6c\u540e\u7684\u94fe\u8868\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><img decoding=\"async\" alt=\"\" src=\"https:\/\/assets.leetcode.com\/uploads\/2021\/02\/19\/rev1ex1.jpg\"><\/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><img decoding=\"async\" alt=\"\" src=\"https:\/\/assets.leetcode.com\/uploads\/2021\/02\/19\/rev1ex2.jpg\"><\/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<p><strong>\u8fdb\u9636\uff1a<\/strong>\u94fe\u8868\u53ef\u4ee5\u9009\u7528\u8fed\u4ee3\u6216\u9012\u5f52\u65b9\u5f0f\u5b8c\u6210\u53cd\u8f6c\u3002\u4f60\u80fd\u5426\u7528\u4e24\u79cd\u65b9\u6cd5\u89e3\u51b3\u8fd9\u9053\u9898\uff1f<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u521d\u59cb\u4ee3\u7801<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/**\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 *\/<\/mark>\nclass Solution {\npublic:\n    ListNode* reverseList(ListNode* head) {\n\n    }\n};<\/code><\/pre>\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>\u9012\u5f52\uff0c\u8fed\u4ee3<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u5148\u8bd5\u7740\u7528\u9012\u5f52\u89e3\u51b3\u3002<\/p>\n\n\n\n<p>\u5f88\u660e\u663e\uff0c\u5c06\u5c3e\u8282\u70b9\u7684next\u6307\u5411\u5176\u4e0a\u4e00\u4e2a\u8282\u70b9\uff0c\u518d\u5c06\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684next\u7f6e\u7a7a\u5c31\u80fd\u5b8c\u6210\u94fe\u8868\u9006\u7f6e\u3002\u6d41\u7a0b\u56fe\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"1024\" data-id=\"1137\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/reverseList.png\" alt=\"\" class=\"wp-image-1137\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/reverseList.png 912w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/reverseList-267x300.png 267w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/reverseList-768x862.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><\/figure>\n<\/figure>\n\n\n\n<p>\u4ee5\u5c3e\u8282\u70b9\u4e3a\u4f8b\u3002\u6211\u4eec\u9700\u8981\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n\n\n\n<ul>\n<li>\u5c3e\u8282\u70b9\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684next<\/li>\n\n\n\n<li>\u5c3e\u8282\u70b9\u672c\u8eab<\/li>\n\n\n\n<li>\u5c3e\u8282\u70b9\u7684next<\/li>\n<\/ul>\n\n\n\n<p>\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u4ee3\u7801<\/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><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/**\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 *\/<\/mark>\nclass Solution {\npublic:\n    ListNode* reverseList(ListNode* head) {\n        if(head==NULL||head->next==NULL)\n            return head;\n        ListNode*tmp=reverseList(head->next);\n        head->next->next=head;\n        head->next=NULL;\n        return tmp;\n    }\n};<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<ul>\n<li>head-&gt;next-&gt;next\u548chead-&gt;next\u7684\u64cd\u4f5c\u4e0d\u80fd\u5bf9\u8c03\u3002\u5148\u6539\u53d8head-&gt;next\u7684\u8bddhead-&gt;next-&gt;next\u7684\u6570\u636e\u5c31\u4e22\u5931\u4e86\u3002<\/li>\n\n\n\n<li>\u4e3a\u4ec0\u4e48\u9700\u8981\u65b0\u5efa\u4e00\u4e2a\u8282\u70b9tmp\uff1f\u56e0\u4e3a\u53cd\u8f6c\u94fe\u8868\u540e\u6700\u540e\u65b0\u7684\u5934\u8282\u70b9\u662f\u539f\u6765\u7684\u5c3e\u8282\u70b9\u3002\u8fd9\u610f\u5473\u7740\u6211\u4eec\u9700\u8981\u4fdd\u5b58\u94fe\u8868\u5c3e\u8282\u70b9\u7684\u5730\u5740\u3002\u5e76\u518d\u6700\u540e\u5c06\u5176\u4f5c\u4e3a\u65b0\u7684\u5934\u8282\u70b9\u8fd4\u56de\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u63a5\u4e0b\u6765\u770b\u770b\u8fed\u4ee3\u600e\u4e48\u5b9e\u73b0\u3002\u8fed\u4ee3\u6bd4\u8d77\u9012\u5f52\u5c31\u5f88\u597d\u61c2\u4e86\u3002<\/p>\n\n\n\n<p>\u548c\u8fed\u4ee3\u4e00\u6837\uff0c\u6211\u4eec\u9700\u8981\uff1a<\/p>\n\n\n\n<ul>\n<li>\u67d0\u8282\u70b9\u7684\u4e0a\u4e00\u4e2a\u8282\u70b9<\/li>\n\n\n\n<li>\u67d0\u8282\u70b9<\/li>\n\n\n\n<li>\u67d0\u8282\u70b9\u7684next<\/li>\n<\/ul>\n\n\n\n<p>\u548c\u9012\u5f52\u4e0d\u540c\u7684\u662f\uff0c\u8fed\u4ee3\u4ece\u94fe\u8868\u5934\u5f00\u59cb\uff0c\u6bd4\u5982\u7ed9\u4e2a[1,2,3]\u7684\u94fe\u8868\uff0c\u5b83\u524d\u4e24\u6b65\u5faa\u73af\u7684\u6d41\u7a0b\u56fe\u5982\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-large has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"864\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/setp1-1024x864.png\" alt=\"\" class=\"wp-image-1142\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/setp1-1024x864.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/setp1-300x253.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/setp1-768x648.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/setp1.png 1110w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-background-color\">\u7b2c\u4e00\u6b65<\/mark><\/em><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large has-custom-border\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"960\" src=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/step2-1024x960.png\" alt=\"\" class=\"wp-image-1143\" style=\"border-style:none;border-width:0px;border-radius:0px\" srcset=\"https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/step2-1024x960.png 1024w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/step2-300x281.png 300w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/step2-768x720.png 768w, https:\/\/white-night.club\/wp-content\/uploads\/2023\/04\/step2.png 1129w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><em><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-background-color\">\u7b2c\u4e8c\u6b65<\/mark><\/em><\/figcaption><\/figure>\n\n\n\n<p>\u5176\u5b9e\u5c31\u662f\u8981\u7406\u89e3\u597d\u201c\u5730\u5740\u548c\u94fe\u8868\u8282\u70b9\u201c\u4e4b\u95f4\u7684\u5173\u7cfb\u3002\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b<\/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><mark style=\"background-color:rgba(0, 0, 0, 0);color:#00ff2f\" class=\"has-inline-color\">\/**\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 *\/<\/mark>\nclass Solution {\npublic:\n    ListNode* reverseList(ListNode* head) {\n        ListNode*end=head;\n        ListNode*pre=NULL;\n        while(end)\n        {\n            ListNode*tmp=end->next;\n            end->next=pre;\n            pre=end;\n            end=tmp;\n        }\n        return pre;\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode\u9898\u76ee\uff1a\u9012\u5f52\u4e0e\u8fed\u4ee3<\/p>\n","protected":false},"author":1,"featured_media":1137,"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\/1136"}],"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=1136"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/1136\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media\/1137"}],"wp:attachment":[{"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/media?parent=1136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=1136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=1136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}