{"id":695,"date":"2020-09-26T11:11:51","date_gmt":"2020-09-26T03:11:51","guid":{"rendered":"http:\/\/39.96.58.60\/?p=695"},"modified":"2022-10-18T16:38:16","modified_gmt":"2022-10-18T08:38:16","slug":"leetcode-%e9%9d%a2%e8%af%95%e9%a2%98-02-05-%e9%93%be%e8%a1%a8%e6%b1%82%e5%92%8c","status":"publish","type":"post","link":"http:\/\/www.yatenglg.cn\/blog\/?p=695","title":{"rendered":"Leetcode \u9762\u8bd5\u9898 02.05. \u94fe\u8868\u6c42\u548c"},"content":{"rendered":"<p>\u7ed9\u5b9a\u4e24\u4e2a\u7528\u94fe\u8868\u8868\u793a\u7684\u6574\u6570\uff0c\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u4e00\u4e2a\u6570\u4f4d\u3002<\/p>\n<p>\u8fd9\u4e9b\u6570\u4f4d\u662f\u53cd\u5411\u5b58\u653e\u7684\uff0c\u4e5f\u5c31\u662f\u4e2a\u4f4d\u6392\u5728\u94fe\u8868\u9996\u90e8\u3002<\/p>\n<p>\u7f16\u5199\u51fd\u6570\u5bf9\u8fd9\u4e24\u4e2a\u6574\u6570\u6c42\u548c\uff0c\u5e76\u7528\u94fe\u8868\u5f62\u5f0f\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>(7 -&gt; 1 -&gt; 6) + (5 -&gt; 9 -&gt; 2)\uff0c\u5373617 + 295\n\n<strong>\u8f93\u51fa\uff1a<\/strong>2 -&gt; 1 -&gt; 9\uff0c\u5373912\n\n<\/pre>\n<p><strong>\u8fdb\u9636\uff1a<\/strong>\u5047\u8bbe\u8fd9\u4e9b\u6570\u4f4d\u662f\u6b63\u5411\u5b58\u653e\u7684\uff0c\u8bf7\u518d\u505a\u4e00\u904d\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><strong>\u8f93\u5165\uff1a<\/strong>(6 -&gt; 1 -&gt; 7) + (2 -&gt; 9 -&gt; 5)\uff0c\u5373617 + 295\n\n<strong>\u8f93\u51fa\uff1a<\/strong>9 -&gt; 1 -&gt; 2\uff0c\u5373912\n\n<\/pre>\n<p>**\u96be\u5ea6**: Medium<\/p>\n<p>**\u6807\u7b7e**: \u94fe\u8868\u3001 \u6570\u5b66\u3001<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism undefined-numbers lang-python\" data-lang=\"Python\"><code>\n# -*- coding: utf-8 -*-\n# @Author  : LG\n\n\"\"\"\n\u6267\u884c\u7528\u65f6\uff1a76 ms, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e8661.41% \u7684\u7528\u6237\n\u5185\u5b58\u6d88\u8017\uff1a13.8 MB, \u5728\u6240\u6709 Python3 \u63d0\u4ea4\u4e2d\u51fb\u8d25\u4e86100.00% \u7684\u7528\u6237\n\n\u89e3\u9898\u601d\u8def\uff1a\n    \u4f7f\u7528\u53cc\u6307\u9488\u5206\u522b\u904d\u5386\u4e24\u4e2a\u94fe\u8868\uff0c\u4f7f\u7528\u4e00\u4e2a\u6570\u8bb0\u5f55\u8fdb\u4f4d\u3002\n    \u82e5\u53cc\u6307\u9488\u4e0e\u8fdb\u4f4d\u5747\u7a7a\u65f6\uff0c\u7ed3\u675f\u3002\n\"\"\"\n\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, x):\n#         self.val = x\n#         self.next = None\n\nclass Solution:\n    def addTwoNumbers(self, l1: ListNode, l2: ListNode) -&gt; ListNode:\n        p, q = l1, l2\n        head = o = ListNode(0)\n        add = 0\n\n        while (p or q or add):\n\n            if p:\n                add = p.val + add\n                p = p.next\n            if q:\n                add = q.val + add\n                q = q.next\n            o.next = ListNode((add % 10))\n            o = o.next\n            add = add \/\/ 10\n\n        return head.next<\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u5b9a\u4e24\u4e2a\u7528\u94fe\u8868\u8868\u793a\u7684\u6574\u6570\uff0c\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u4e00\u4e2a\u6570\u4f4d\u3002 \u8fd9\u4e9b\u6570\u4f4d\u662f\u53cd\u5411\u5b58\u653e\u7684\uff0c\u4e5f\u5c31\u662f\u4e2a\u4f4d\u6392\u5728\u94fe\u8868\u9996\u90e8\u3002 \u7f16\u5199\u51fd\u6570\u5bf9\u8fd9&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/695"}],"collection":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=695"}],"version-history":[{"count":1,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/695\/revisions"}],"predecessor-version":[{"id":696,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=\/wp\/v2\/posts\/695\/revisions\/696"}],"wp:attachment":[{"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=695"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.yatenglg.cn\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}