{"id":896,"date":"2023-07-23T09:34:49","date_gmt":"2023-07-23T09:34:49","guid":{"rendered":"https:\/\/blog.liuyingjie.com.cn\/?p=896"},"modified":"2023-08-13T08:14:25","modified_gmt":"2023-08-13T08:14:25","slug":"21-%e5%90%88%e5%b9%b6%e4%b8%a4%e4%b8%aa%e6%9c%89%e5%ba%8f%e9%93%be%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/blog.liuyingjie.com.cn\/?p=896","title":{"rendered":"21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868"},"content":{"rendered":"\n<p>\u65b9\u6cd5\u4e00\u3001\u9012\u5f52<\/p>\n\n\n\n<p>List1\u6216List2\u4e00\u5f00\u59cb\u5c31\u662f\u7a7a\u94fe\u8868\uff0c\u90a3\u4e48\u4e0d\u9700\u8981\u4efb\u4f55\u64cd\u4f5c\u76f4\u63a5\u8fd4\u56de\u975e\u7a7a\u94fe\u8868\u3002\u5426\u5219\u6211\u4eec\u5c31\u8981\u5224\u65adList1\u6216List2\u54ea\u4e00\u4e2a\u94fe\u8868\u7684\u5934\u8282\u70b9\u7684\u503c\u66f4\u5c0f\uff0c\u7136\u540e\u9012\u5f52\u5730\u51b3\u5b9a\u4e0b\u4e00\u4e2a\u6dfb\u52a0\u5230\u7ed3\u679c\u91cc\u7684\u8282\u70b9\u3002\u5982\u679c\u4e24\u4e2a\u94fe\u8868\u6709\u4e00\u4e2a\u4e3a\u7a7a\uff0c\u9012\u5f52\u7ed3\u675f\u3002<\/p>\n\n\n\n<p>Python3 \u4ee3\u7801\u9898\u89e3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"python\" class=\"language-python\"># Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -&gt; Optional[ListNode]:\n        if list1 is None:\n            return list2\n        elif list2 is None:\n            return list1\n        elif list1.val &lt; list2.val:\n            list1.next = self.mergeTwoLists(list1.next, list2)\n            return list1\n        else:\n            list2.next = self.mergeTwoLists(list1, list2.next)\n            return list2<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/blog.liuyingjie.com.cn\/wp-content\/uploads\/2023\/07\/21.-\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868.svg\"><img decoding=\"async\" src=\"https:\/\/blog.liuyingjie.com.cn\/wp-content\/uploads\/2023\/07\/21.-\u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868.svg\" alt=\"\"\/><\/a><\/figure>\n\n\n\n<p>Source: LeetCode\uff08The title reproduced in this blog is for personal study use only\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65b9\u6cd5\u4e00\u3001\u9012\u5f52 List1\u6216List2\u4e00\u5f00\u59cb\u5c31\u662f\u7a7a\u94fe\u8868\uff0c\u90a3\u4e48\u4e0d\u9700\u8981\u4efb\u4f55\u64cd\u4f5c\u76f4\u63a5\u8fd4\u56de\u975e\u7a7a\u94fe\u8868\u3002\u5426\u5219\u6211\u4eec\u5c31\u8981\u5224\u65adLi &hellip; <a href=\"https:\/\/blog.liuyingjie.com.cn\/?p=896\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-896","post","type-post","status-publish","format-standard","hentry","category-leetcode"],"_links":{"self":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=896"}],"version-history":[{"count":3,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/896\/revisions"}],"predecessor-version":[{"id":996,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=\/wp\/v2\/posts\/896\/revisions\/996"}],"wp:attachment":[{"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.liuyingjie.com.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}