{"id":89946,"date":"2026-08-04T09:40:32","date_gmt":"2026-08-04T01:40:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/89946.html"},"modified":"2026-08-04T09:40:32","modified_gmt":"2026-08-04T01:40:32","slug":"leetcode-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%ef%bd%9cpython-%e8%a7%a3%e6%b3%95%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/89946.html","title":{"rendered":"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3"},"content":{"rendered":"<h2>LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868&#xff5c;Python \u89e3\u6cd5\u8be6\u89e3<\/h2>\n<p>CSDN \u7b97\u6cd5\u4e13\u9898 \u00b7 \u94fe\u8868 | \u96be\u5ea6&#xff1a;\u7b80\u5355<\/p>\n<h3>\u9898\u76ee\u4fe1\u606f<\/h3>\n<ul>\n<li>\u9898\u53f7&#xff1a;21<\/li>\n<li>\u96be\u5ea6&#xff1a;\u7b80\u5355<\/li>\n<li>LeetCode&#xff1a;\u9898\u76ee\u94fe\u63a5<\/li>\n<\/ul>\n<h3>\u9898\u76ee\u63cf\u8ff0<\/h3>\n<p>\u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u5347\u5e8f\u94fe\u8868&#xff0c;\u5e76\u8fd4\u56de\u5176\u5934\u8282\u70b9\u3002\u65b0\u94fe\u8868\u7531\u539f\u94fe\u8868\u8282\u70b9\u62fc\u63a5\u800c\u6210\u3002<\/p>\n<h3>\u793a\u4f8b<\/h3>\n<p>\u8f93\u5165&#xff1a;list1 &#061; [1,2,4], list2 &#061; [1,3,4]<br \/>\n\u8f93\u51fa&#xff1a;[1,1,2,3,4,4]<\/p>\n<h3>\u7ea6\u675f<\/h3>\n<p>\u4e24\u4e2a\u94fe\u8868\u8282\u70b9\u6570\u5747\u4e0d\u8d85\u8fc7 50&#xff1b;\u8282\u70b9\u503c\u6709\u5e8f\u3002<\/p>\n<h3>\u89e3\u9898\u601d\u8def<\/h3>\n<h4>\u6838\u5fc3\u89c2\u5bdf<\/h4>\n<p>\u4f7f\u7528\u54d1\u8282\u70b9\u7edf\u4e00\u5904\u7406\u5934\u8282\u70b9\u3002\u6bd4\u8f83\u4e24\u4e2a\u5f53\u524d\u8282\u70b9&#xff0c;\u628a\u8f83\u5c0f\u8005\u63a5\u5230\u7ed3\u679c\u5c3e\u90e8\u5e76\u79fb\u52a8\u5bf9\u5e94\u6307\u9488&#xff1b;\u4e00\u6761\u94fe\u8868\u8017\u5c3d\u540e&#xff0c;\u5269\u4f59\u90e8\u5206\u672c\u8eab\u6709\u5e8f&#xff0c;\u53ef\u6574\u4f53\u63a5\u4e0a\u3002<\/p>\n<h4>\u63a8\u5bfc\u4e0e\u6267\u884c\u6b65\u9aa4<\/h4>\n<li>\u521b\u5efa dummy \u548c tail<\/li>\n<li>\u6bd4\u8f83 list1 \u4e0e list2 \u5f53\u524d\u503c<\/li>\n<li>\u8fde\u63a5\u8f83\u5c0f\u8282\u70b9\u5e76\u79fb\u52a8\u6307\u9488<\/li>\n<li>\u8fde\u63a5\u672a\u904d\u5386\u5b8c\u7684\u5269\u4f59\u94fe\u8868<\/li>\n<h4>\u4e3a\u4ec0\u4e48\u8fd9\u4e2a\u65b9\u6cd5\u6b63\u786e<\/h4>\n<p>\u7b97\u6cd5\u59cb\u7ec8\u56f4\u7ed5\u4e0a\u8ff0\u6838\u5fc3\u89c2\u5bdf\u7ef4\u62a4\u6709\u6548\u72b6\u6001&#xff0c;\u5e76\u4e14\u6bcf\u4e00\u6b65\u53ea\u6392\u9664\u5df2\u7ecf\u80fd\u591f\u8bc1\u660e\u4e0d\u53ef\u80fd\u4ea7\u751f\u66f4\u4f18\u7b54\u6848\u7684\u60c5\u51b5\u3002\u6309\u7167\u6267\u884c\u6b65\u9aa4\u5904\u7406\u540e&#xff0c;\u6240\u6709\u53ef\u80fd\u5f71\u54cd\u7b54\u6848\u7684\u5143\u7d20\u6216\u8282\u70b9\u90fd\u4f1a\u88ab\u6070\u597d\u68c0\u67e5&#xff0c;\u56e0\u6b64\u4e0d\u4f1a\u9057\u6f0f\u5408\u6cd5\u7b54\u6848&#xff1b;\u72b6\u6001\u66f4\u65b0\u53c8\u4e25\u683c\u9075\u5b88\u9898\u76ee\u7ea6\u675f&#xff0c;\u6240\u4ee5\u6700\u7ec8\u7ed3\u679c\u6709\u6548\u3002<\/p>\n<p>\u4ece\u8fb9\u754c\u770b&#xff0c;\u7a7a\u533a\u95f4\u3001\u5355\u4e2a\u5143\u7d20\u3001\u5168\u90e8\u76f8\u540c\u6216\u5b8c\u5168\u4e0d\u5339\u914d\u7b49\u60c5\u51b5\u90fd\u4f1a\u843d\u5165\u521d\u59cb\u5316\u6761\u4ef6\u6216\u5faa\u73af\u7ec8\u6b62\u6761\u4ef6&#xff0c;\u4e0d\u9700\u8981\u4f9d\u8d56\u672a\u5b9a\u4e49\u72b6\u6001\u3002\u5b9e\u73b0\u65f6\u518d\u91cd\u70b9\u68c0\u67e5\u4e0b\u6807\u3001\u7a7a\u8282\u70b9\u548c\u91cd\u590d\u5143\u7d20&#xff0c;\u5373\u53ef\u4fdd\u8bc1\u7b97\u6cd5\u5728\u6781\u7aef\u8f93\u5165\u4e0b\u4ecd\u7136\u6210\u7acb\u3002<\/p>\n<h3>Python \u4ee3\u7801<\/h3>\n<p><span class=\"token comment\"># \u89e3\u6cd5\u6838\u5fc3&#xff1a;\u4f7f\u7528\u54d1\u8282\u70b9\u7edf\u4e00\u5904\u7406\u5934\u8282\u70b9\u3002\u6bd4\u8f83\u4e24\u4e2a\u5f53\u524d\u8282\u70b9&#xff0c;\u628a\u8f83\u5c0f\u8005\u63a5\u5230\u7ed3\u679c\u5c3e\u90e8\u5e76\u79fb\u52a8\u5bf9\u5e94\u6307\u9488&#xff1b;\u4e00\u6761\u94fe\u8868\u8017\u5c3d\u540e&#xff0c;\u5269\u4f59\u90e8\u5206\u672c\u8eab\u6709\u5e8f&#xff0c;\u53ef\u6574\u4f53\u63a5\u4e0a\u3002<\/span><br \/>\n<span class=\"token comment\"># \u5b9e\u73b0\u6b65\u9aa4&#xff1a;<\/span><br \/>\n<span class=\"token comment\"># 1. \u521b\u5efa dummy \u548c tail<\/span><br \/>\n<span class=\"token comment\"># 2. \u6bd4\u8f83 list1 \u4e0e list2 \u5f53\u524d\u503c<\/span><br \/>\n<span class=\"token comment\"># 3. \u8fde\u63a5\u8f83\u5c0f\u8282\u70b9\u5e76\u79fb\u52a8\u6307\u9488<\/span><br \/>\n<span class=\"token comment\"># 4. \u8fde\u63a5\u672a\u904d\u5386\u5b8c\u7684\u5269\u4f59\u94fe\u8868<\/span><\/p>\n<p><span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> Optional<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">ListNode<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> val<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">next<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">None<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>val <span class=\"token operator\">&#061;<\/span> val<br \/>\n        self<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">next<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Solution<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">mergeTwoLists<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> list1<span class=\"token punctuation\">:<\/span> Optional<span class=\"token punctuation\">[<\/span>ListNode<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> list2<span class=\"token punctuation\">:<\/span> Optional<span class=\"token punctuation\">[<\/span>ListNode<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> Optional<span class=\"token punctuation\">[<\/span>ListNode<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        dummy <span class=\"token operator\">&#061;<\/span> ListNode<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u54d1\u8282\u70b9\u7528\u4e8e\u7edf\u4e00\u5904\u7406\u5934\u8282\u70b9\u53ef\u80fd\u53d8\u5316\u7684\u60c5\u51b5<\/span><br \/>\n        tail <span class=\"token operator\">&#061;<\/span> dummy<br \/>\n        <span class=\"token keyword\">while<\/span> list1 <span class=\"token keyword\">and<\/span> list2<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> list1<span class=\"token punctuation\">.<\/span>val <span class=\"token operator\">&lt;<\/span> list2<span class=\"token punctuation\">.<\/span>val<span class=\"token punctuation\">:<\/span><br \/>\n                tail<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span> <span class=\"token operator\">&#061;<\/span> list1<br \/>\n                list1 <span class=\"token operator\">&#061;<\/span> list1<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span><br \/>\n            <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n                tail<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span> <span class=\"token operator\">&#061;<\/span> list2<br \/>\n                list2 <span class=\"token operator\">&#061;<\/span> list2<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span><br \/>\n            tail <span class=\"token operator\">&#061;<\/span> tail<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span><br \/>\n        tail<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span> <span class=\"token operator\">&#061;<\/span> list1 <span class=\"token keyword\">if<\/span> list1 <span class=\"token keyword\">else<\/span> list2<br \/>\n        <span class=\"token keyword\">return<\/span> dummy<span class=\"token punctuation\">.<\/span><span class=\"token builtin\">next<\/span><\/p>\n<h3>\u590d\u6742\u5ea6\u5206\u6790<\/h3>\n<ul>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(m&#043;n)<\/li>\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(1)<\/li>\n<\/ul>\n<h3>\u6613\u9519\u70b9<\/h3>\n<p>\u5faa\u73af\u7ed3\u675f\u540e\u4e0d\u8981\u6f0f\u63a5\u5269\u4f59\u8282\u70b9&#xff1b;\u8fd4\u56de dummy.next\u3002<\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>\u8fd9\u9053\u9898\u7684\u5173\u952e\u662f&#xff1a;\u4f7f\u7528\u54d1\u8282\u70b9\u7edf\u4e00\u5904\u7406\u5934\u8282\u70b9\u3002\u7406\u89e3\u8fd9\u4e00\u70b9\u540e&#xff0c;\u518d\u7ed3\u5408\u8fb9\u754c\u6761\u4ef6\u68c0\u67e5&#xff0c;\u4ee3\u7801\u5c31\u80fd\u4fdd\u6301\u6e05\u6670\u4e14\u7a33\u5b9a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868&#xff5c;Python \u89e3\u6cd5\u8be6\u89e3 CSDN \u7b97\u6cd5\u4e13\u9898 \u00b7 \u94fe\u8868 | \u96be\u5ea6&#xff1a;\u7b80\u5355 \u9898\u76ee\u4fe1\u606f<br \/>\n\u9898\u53f7&#xff1a;21\u96be\u5ea6&#xff1a;\u7b80\u5355LeetCode&#xff1a;\u9898\u76ee\u94fe\u63a5<br \/>\n\u9898\u76ee\u63cf\u8ff0<br \/>\n\u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u5347\u5e8f\u94fe\u8868&#xff0c;\u5e76\u8fd4\u56de\u5176\u5934\u8282\u70b9\u3002\u65b0\u94fe\u8868\u7531\u539f\u94fe\u8868\u8282\u70b9\u62fc\u63a5\u800c\u6210\u3002<br \/>\n\u793a\u4f8b<br \/>\n\u8f93\u5165&#xff1a;list1  [1,2,4], list2  [1,3,4]<br \/>\n\u8f93\u51fa&#xff1a;[1,1,2<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9137,2692,81,427,2640],"topic":[],"class_list":["post-89946","post","type-post","status-publish","format-standard","hentry","category-server","tag-atomgit","tag-leetcode","tag-python","tag-427","tag-2640"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/89946.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868&#xff5c;Python \u89e3\u6cd5\u8be6\u89e3 CSDN \u7b97\u6cd5\u4e13\u9898 \u00b7 \u94fe\u8868 | \u96be\u5ea6&#xff1a;\u7b80\u5355 \u9898\u76ee\u4fe1\u606f \u9898\u53f7&#xff1a;21\u96be\u5ea6&#xff1a;\u7b80\u5355LeetCode&#xff1a;\u9898\u76ee\u94fe\u63a5 \u9898\u76ee\u63cf\u8ff0 \u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u5347\u5e8f\u94fe\u8868&#xff0c;\u5e76\u8fd4\u56de\u5176\u5934\u8282\u70b9\u3002\u65b0\u94fe\u8868\u7531\u539f\u94fe\u8868\u8282\u70b9\u62fc\u63a5\u800c\u6210\u3002 \u793a\u4f8b \u8f93\u5165&#xff1a;list1 [1,2,4], list2 [1,3,4] \u8f93\u51fa&#xff1a;[1,1,2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/89946.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-04T01:40:32+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89946.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/89946.html\",\"name\":\"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-04T01:40:32+00:00\",\"dateModified\":\"2026-08-04T01:40:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/89946.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/89946.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89946.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/89946.html","og_locale":"zh_CN","og_type":"article","og_title":"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868&#xff5c;Python \u89e3\u6cd5\u8be6\u89e3 CSDN \u7b97\u6cd5\u4e13\u9898 \u00b7 \u94fe\u8868 | \u96be\u5ea6&#xff1a;\u7b80\u5355 \u9898\u76ee\u4fe1\u606f \u9898\u53f7&#xff1a;21\u96be\u5ea6&#xff1a;\u7b80\u5355LeetCode&#xff1a;\u9898\u76ee\u94fe\u63a5 \u9898\u76ee\u63cf\u8ff0 \u5c06\u4e24\u4e2a\u5347\u5e8f\u94fe\u8868\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u7684\u5347\u5e8f\u94fe\u8868&#xff0c;\u5e76\u8fd4\u56de\u5176\u5934\u8282\u70b9\u3002\u65b0\u94fe\u8868\u7531\u539f\u94fe\u8868\u8282\u70b9\u62fc\u63a5\u800c\u6210\u3002 \u793a\u4f8b \u8f93\u5165&#xff1a;list1 [1,2,4], list2 [1,3,4] \u8f93\u51fa&#xff1a;[1,1,2","og_url":"https:\/\/www.wsisp.com\/helps\/89946.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-04T01:40:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/89946.html","url":"https:\/\/www.wsisp.com\/helps\/89946.html","name":"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-04T01:40:32+00:00","dateModified":"2026-08-04T01:40:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/89946.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/89946.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/89946.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"LeetCode 21. \u5408\u5e76\u4e24\u4e2a\u6709\u5e8f\u94fe\u8868\uff5cPython \u89e3\u6cd5\u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=89946"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89946\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=89946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=89946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=89946"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=89946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}