{"id":2489,"date":"2022-01-29T19:38:44","date_gmt":"2022-01-29T11:38:44","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2489"},"modified":"2022-01-29T19:38:46","modified_gmt":"2022-01-29T11:38:46","slug":"leetcodeday113","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/29\/leetcodeday113\/","title":{"rendered":"leetcodeday113 &#8211;\u8def\u5f84\u603b\u548c II"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;<code>root<\/code>&nbsp;\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u548c&nbsp;<code>targetSum<\/code>&nbsp;\uff0c\u627e\u51fa\u6240\u6709&nbsp;<strong>\u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9<\/strong>&nbsp;\u8def\u5f84\u603b\u548c\u7b49\u4e8e\u7ed9\u5b9a\u76ee\u6807\u548c\u7684\u8def\u5f84\u3002<\/p>\n\n\n\n<p><strong>\u53f6\u5b50\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\/01\/18\/pathsumii1.jpg\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;&#91;5,4,11,2],&#91;5,8,4,5]]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 2\uff1a<\/strong><img alt=\"\" src=\"https:\/\/assets.leetcode.com\/uploads\/2021\/01\/18\/pathsum2.jpg\"><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;1,2,3], targetSum = 5\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;]<\/code><\/pre>\n\n\n\n<p><strong>\u793a\u4f8b 3\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u8f93\u5165\uff1a<\/strong>root = &#91;1,2], targetSum = 0\n<strong>\u8f93\u51fa\uff1a<\/strong>&#91;]<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># &#91;113] \u8def\u5f84\u603b\u548c II\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 pathSum(self, root: Optional&#91;TreeNode], targetSum: int) -> List&#91;List&#91;int]]:\r\n        res=list()\r\n        rev=list()\r\n        \r\n        def subisBalanced(root,deep,target,rev):\r\n            if  root.left==None and root.right==None and deep==target:   \r\n                res.append(rev)\r\n                return \r\n            if root.left!=None:\r\n                deepl=deep+ root.left.val\r\n                \r\n                subisBalanced(root.left,deepl,target,rev+ &#91;root.left.val])\r\n\r\n                \r\n            if  root.right!=None:\r\n                deepr=deep+root.right.val\r\n               \r\n                subisBalanced(root.right,deepr,target,rev+&#91;root.right.val])\r\n\r\n        if root==None:\r\n            return &#91;]\r\n        else: \r\n            rev.append(root.val)\r\n            subisBalanced(root,root.val, targetSum,rev)\r\n            return res\r\n        \r\n# @lc code=end\r\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"894\" height=\"239\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-312.png\" alt=\"\" class=\"wp-image-2490\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-312.png 894w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-312-300x80.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-312-768x205.png 768w\" sizes=\"(max-width: 894px) 100vw, 894px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;root&nbsp;\u548c\u4e00\u4e2a\u6574\u6570\u76ee\u6807\u548c&nbsp;targetSum&nbsp;\uff0c &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/29\/leetcodeday113\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday113 &#8211;\u8def\u5f84\u603b\u548c II<\/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\/2489"}],"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=2489"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2489\/revisions"}],"predecessor-version":[{"id":2491,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2489\/revisions\/2491"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2489"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}