{"id":1084,"date":"2023-04-27T14:31:29","date_gmt":"2023-04-27T06:31:29","guid":{"rendered":"https:\/\/white-night.club\/?p=1084"},"modified":"2023-11-09T11:07:56","modified_gmt":"2023-11-09T03:07:56","slug":"ad5","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/04\/27\/ad5\/","title":{"rendered":"203.\u00a0\u79fb\u9664\u94fe\u8868\u5143\u7d20"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9 head \u548c\u4e00\u4e2a\u6574\u6570 val \uff0c\u8bf7\u4f60\u5220\u9664\u94fe\u8868\u4e2d\u6240\u6709\u6ee1\u8db3 Node.val == val \u7684\u8282\u70b9\uff0c\u5e76\u8fd4\u56de\u65b0\u7684\u5934\u8282\u70b9 \u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image has-custom-border\"><img decoding=\"async\" src=\"https:\/\/assets.leetcode.com\/uploads\/2021\/03\/06\/removelinked-list.jpg\" alt=\"\" style=\"border-style:none;border-width:0px;border-radius:0px\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\u8f93\u5165\uff1a<\/strong>head = [1,2,6,3,4,5,6], val = 6\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,2,3,4,5]\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 = [], val = 1\n<strong>\u8f93\u51fa\uff1a<\/strong>[]\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 = [7,7,7,7], val = 7\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>\u5217\u8868\u4e2d\u7684\u8282\u70b9\u6570\u76ee\u5728\u8303\u56f4&nbsp;<code>[0, 10<sup>4<\/sup>]<\/code>&nbsp;\u5185<\/li>\n\n\n\n<li><code>1 &lt;= Node.val &lt;= 50<\/code><\/li>\n\n\n\n<li><code>0 &lt;= val &lt;= 50<\/code><\/li>\n<\/ul>\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* removeElements(ListNode* head, int val) {\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<ul>\n<li><\/li>\n<\/ul>\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<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u53c8\u662f\u94fe\u8868\u76f8\u5173\u7684\u9012\u5f52\u9898\u3002\u610f\u5473\u7740\u6211\u4eec\u8981<mark style=\"background-color:rgba(0, 0, 0, 0);color:#fcb900\" class=\"has-inline-color\">\u7528\u6808\u7684\u601d\u7ef4\uff0c\u4ece\u94fe\u8868\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u5f80\u524d\u770b<\/mark>\u3002<\/p>\n\n\n\n<p>\u6700\u540e\u4e00\u4e2a\u8282\u70b9\u7684val\u53ef\u80fd\u76f8\u7b49\uff0c\u6240\u4ee5\u6211\u4eec\u9012\u5f52\u5e94\u8be5\u9012\u5f52\u5230\u94fe\u8868\u6700\u540e\u7684\u7a7a\u8282\u70b9NULL\u3002\u9012\u5f52\u5230\u8be5\u8282\u70b9\u65f6\uff0c\u5c06NULL\u8fd4\u56de\u7ed9\u94fe\u8868\u5c3e\u8282\u70b9\u7684next\u3002\u8fd9\u6837\u5982\u679c\u94fe\u8868\u4e2d\u5c31\u4e00\u4e2a\u8282\u70b9\uff0c\u5220\u9664\u8be5\u8282\u70b9\u540e\u94fe\u8868\u4e5f\u80fd\u7f6e\u7a7a\u3002<\/p>\n\n\n\n<p>\u548c\u7528\u8fed\u4ee3\u6cd5\u5220\u8282\u70b9\u4e00\u6837\uff0c\u6211\u4eec\u8981\u5220\u9664B\u8282\u70b9\u524d\uff0c\u5f97\u6709\u5b83\u7684\u4e0a\u4e00\u4e2a\u8282\u70b9\u7684next\u3002\u8fd9\u6837\u6211\u4eec\u624d\u80fd\u628aA\u7684next\u6307\u9488\u4ece\u6307\u5411B\u8282\u70b9\u6539\u4e3a\u6307\u5411C\u8282\u70b9\u3002\u90a3\u4e48\u9012\u5f52\u7684\u65f6\u5019\u4e5f\u662f\u4e00\u6837\uff0c\u4ee3\u7801\u5982\u4e0b<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>head-&gt;next=removeElements(head-&gt;next,val);<\/em><\/strong><\/p>\n\n\n\n<p>\u9012\u5f52\u5230\u6700\u540e\u65f6\u9700\u8981\u5224\u65ad\u662f\u5426\u7b49\u4e8e\u7ed9\u5b9a\u7684val\uff0c\u76f8\u7b49\u5c31\u5c06B-&gt;next\u4f5c\u4e3a\u8fd4\u56de\u503c\uff0c\u8fd4\u56de\u7ed9A-&gt;next\uff0c\u4ece\u800c\u5b9e\u73b0A\u7684next\u6307\u5411B-&gt;next\u5373C\u8282\u70b9\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong>\u5b8c\u6574\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* removeElements(ListNode* head, int val) {\n        if(head==NULL)\n            return NULL;\n        head->next=removeElements(head->next,val);\n        if(head->val==val)\n            return head->next;\n        else\n            return head;\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode\u9898\u76ee\uff1a\u94fe\u8868\u9012\u5f52<\/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\/1084"}],"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=1084"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/1084\/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=1084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=1084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=1084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}