{"id":2614,"date":"2022-02-04T14:47:12","date_gmt":"2022-02-04T06:47:12","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2614"},"modified":"2022-02-04T14:47:13","modified_gmt":"2022-02-04T06:47:13","slug":"leetcodeday129","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday129\/","title":{"rendered":"leetcodeday129&#8211;\u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;<code>root<\/code>&nbsp;\uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u5b58\u653e\u6709\u4e00\u4e2a&nbsp;<code>0<\/code>&nbsp;\u5230&nbsp;<code>9<\/code>&nbsp;\u4e4b\u95f4\u7684\u6570\u5b57\u3002<\/p>\n\n\n\n<p>\u6bcf\u6761\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84\u90fd\u4ee3\u8868\u4e00\u4e2a\u6570\u5b57\uff1a<\/p>\n\n\n\n<ul><li>\u4f8b\u5982\uff0c\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u7684\u8def\u5f84&nbsp;<code>1 -&gt; 2 -&gt; 3<\/code>&nbsp;\u8868\u793a\u6570\u5b57&nbsp;<code>123<\/code>&nbsp;\u3002<\/li><\/ul>\n\n\n\n<p>\u8ba1\u7b97\u4ece\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u751f\u6210\u7684&nbsp;<strong>\u6240\u6709\u6570\u5b57\u4e4b\u548c<\/strong>&nbsp;\u3002<\/p>\n\n\n\n<p><strong>\u53f6\u8282\u70b9<\/strong>&nbsp;\u662f\u6307\u6ca1\u6709\u5b50\u8282\u70b9\u7684\u8282\u70b9\u3002<\/p>\n\n\n\n<p><strong>\u793a\u4f8b 1\uff1a<\/strong><img alt=\"\" src=\"https:\/\/assets.leetcode.com\/uploads\/2021\/02\/19\/num1tree.jpg\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;1,2,3]\n<strong>\u8f93\u51fa\uff1a<\/strong>25\n<strong>\u89e3\u91ca\uff1a<\/strong>\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 1-&gt;2 \u4ee3\u8868\u6570\u5b57 12\n\u4ece\u6839\u5230\u53f6\u5b50\u8282\u70b9\u8def\u5f84 1-&gt;3 \u4ee3\u8868\u6570\u5b57 13\n\u56e0\u6b64\uff0c\u6570\u5b57\u603b\u548c = 12 + 13 = 25<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># &#91;129] \u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c\r\n#\r\n\r\n# @lc code=start\r\n# Definition for a binary tree node.\r\n# class TreeNode:\r\n#     def __init__(self, val=0, left=None, right=None):\r\n#         self.val = val\r\n#         self.left = left\r\n#         self.right = right\r\nclass Solution:\r\n    def sumNumbers(self, root: TreeNode) -> int:\r\n        nums=&#91;0]\r\n        def subisBalanced(root,deep):\r\n            if root.left!=None:\r\n                deepl=deep*10+root.left.val\r\n                subisBalanced(root.left,deepl)          \r\n            if  root.right!=None:\r\n                deepr=deep*10+root.right.val \r\n                subisBalanced(root.right,deepr)\r\n            \r\n            if  root.left==None and root.right==None:\r\n                nums&#91;0]=nums&#91;0]+deep    \r\n                return\r\n        if root==None:\r\n            return 0\r\n        else:\r\n            subisBalanced(root,root.val)\r\n            return nums&#91;0]\r\n# @lc code=end\r\n\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"859\" height=\"233\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-39.png\" alt=\"\" class=\"wp-image-2615\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-39.png 859w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-39-300x81.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/02\/image-39-768x208.png 768w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e00\u4e2a\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;root&nbsp;\uff0c\u6811\u4e2d\u6bcf\u4e2a\u8282\u70b9\u90fd\u5b58\u653e\u6709\u4e00\u4e2a&nbsp;0&nbsp;\u5230&#038; &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/02\/04\/leetcodeday129\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday129&#8211;\u6c42\u6839\u8282\u70b9\u5230\u53f6\u8282\u70b9\u6570\u5b57\u4e4b\u548c<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2614"}],"collection":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/comments?post=2614"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2614\/revisions"}],"predecessor-version":[{"id":2616,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2614\/revisions\/2616"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2614"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}