{"id":1109,"date":"2023-04-28T14:05:22","date_gmt":"2023-04-28T06:05:22","guid":{"rendered":"https:\/\/white-night.club\/?p=1109"},"modified":"2023-11-09T11:07:55","modified_gmt":"2023-11-09T03:07:55","slug":"ad6","status":"publish","type":"post","link":"https:\/\/white-night.club\/index.php\/2023\/04\/28\/ad6\/","title":{"rendered":"21.\u00a0\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868"},"content":{"rendered":"\n<p>\u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u4e3a\u4e00\u4e2a\u65b0\u7684&nbsp;<strong>\u5347\u5e8f<\/strong>&nbsp;\u94fe\u8868\u5e76\u8fd4\u56de\u3002\u65b0\u94fe\u8868\u662f\u901a\u8fc7\u62fc\u63a5\u7ed9\u5b9a\u7684\u4e24\u4e2a\u94fe\u8868\u7684\u6240\u6709\u8282\u70b9\u7ec4\u6210\u7684\u3002&nbsp;<\/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\/2020\/10\/03\/merge_ex1.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>l1 = [1,2,4], l2 = [1,3,4]\n<strong>\u8f93\u51fa\uff1a<\/strong>[1,1,2,3,4,4]\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>l1 = [], l2 = []\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>l1 = [], l2 = [0]\n<strong>\u8f93\u51fa\uff1a<\/strong>[0]<\/pre>\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* mergeTwoLists(ListNode* list1, ListNode* list2) {\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<\/em><\/cite><\/blockquote>\n\n\n\n<p>\u9012\u5f52\u9898\u771f\u7684\u662f\u201c\u4e00\u5199\u5c31\u4e0d\u4f1a\uff0c\u4e00\u770b\u5c31\u641e\u61c2\u201d\u3002<\/p>\n\n\n\n<p>\u9012\u5f52\u7684\u201c\u9012\u201d\u662f\u4e2a\u538b\u6808\u7684\u8fc7\u7a0b\uff0c\u6240\u4ee5\u9012\u5f52\u5230\u6700\u540e\u6808\u9876\u5e94\u8be5\u662f\u94fe\u8868\u7684\u5c3e\u8282\u70b9\u6216NULL\u3002<\/p>\n\n\n\n<p>A\uff0cB\u4e24\u4e2a\u94fe\u8868\u957f\u5ea6\u53ef\u80fd\u4e0d\u540c\u3002\u53ef\u80fdA\u5df2\u7ecf\u9012\u5f52\u5230\u4e86NULL\u4f46B\u540e\u9762\u8fd8\u63a5\u7740\u4e00\u957f\u4e32\u8282\u70b9\u3002\u53c8\u7531\u4e8e\u4e24\u4e2a\u94fe\u8868\u90fd\u662f\u6709\u5e8f\u7684\uff0c\u90a3\u4e48\u6b64\u65f6\u76f4\u63a5\u628aB\u94fe\u8868\u5269\u4e0b\u7684\u8282\u70b9\u63a5\u5230A\u7684\u5c3e\u8282\u70b9\u4e0a\u5c31\u597d\u3002\u53cd\u4e4b\u4ea6\u7136\uff0c\u53ef\u4ee5\u5f97\u5230\u4ee3\u7801\uff1a<\/p>\n\n\n\n<p class=\"has-text-align-center\"><strong><em>return list1==NULL ? list2:list1;<\/em><\/strong><\/p>\n\n\n\n<p>\u4ece\u94fe\u8868\u5c3e\u5f80\u524d\u201c\u5f52\u201d\uff0c\u8fd9\u662f\u4e2a\u51fa\u6808\u7684\u64cd\u4f5c\uff0c\u76f4\u63a5\u6bd4\u5927\u5c0f\u7136\u540e\u62fc\u63a5\u5c31\u884c\u4e86\uff0c\u6bd4\u8f83\u7b80\u5355\u6ca1\u5565\u8bf4\u7684\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* mergeTwoLists(ListNode* list1, ListNode* list2) {\n        if(list1==NULL||list2==NULL)\n            return list1==NULL ? list2:list1;\n\n        if(list1->val&lt;list2->val)\n        {\n            list1->next=mergeTwoLists(list1->next,list2);\n            return list1;\n        }else\n        {\n            list2->next=mergeTwoLists(list1,list2->next);\n            return list2;\n        }\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode\u9898\u76ee\uff1a\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\/1109"}],"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=1109"}],"version-history":[{"count":0,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/posts\/1109\/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=1109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/categories?post=1109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/white-night.club\/index.php\/wp-json\/wp\/v2\/tags?post=1109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}