{"id":2486,"date":"2022-01-29T17:15:19","date_gmt":"2022-01-29T09:15:19","guid":{"rendered":"http:\/\/139.9.1.231\/?p=2486"},"modified":"2022-01-29T17:15:21","modified_gmt":"2022-01-29T09:15:21","slug":"leetcodeday112","status":"publish","type":"post","link":"http:\/\/139.9.1.231\/index.php\/2022\/01\/29\/leetcodeday112\/","title":{"rendered":"leetcodeday112&#8211;\u8def\u5f84\u603b\u548c"},"content":{"rendered":"\n<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;<code>root<\/code>&nbsp;\u548c\u4e00\u4e2a\u8868\u793a\u76ee\u6807\u548c\u7684\u6574\u6570&nbsp;<code>targetSum<\/code>&nbsp;\u3002\u5224\u65ad\u8be5\u6811\u4e2d\u662f\u5426\u5b58\u5728&nbsp;<strong>\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9<\/strong>&nbsp;\u7684\u8def\u5f84\uff0c\u8fd9\u6761\u8def\u5f84\u4e0a\u6240\u6709\u8282\u70b9\u503c\u76f8\u52a0\u7b49\u4e8e\u76ee\u6807\u548c&nbsp;<code>targetSum<\/code>&nbsp;\u3002\u5982\u679c\u5b58\u5728\uff0c\u8fd4\u56de&nbsp;<code>true<\/code>&nbsp;\uff1b\u5426\u5219\uff0c\u8fd4\u56de&nbsp;<code>false<\/code>&nbsp;\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<pre class=\"wp-block-code\"><code>#\r\n# @lc app=leetcode.cn id=112 lang=python3\r\n#\r\n# &#91;112] \u8def\u5f84\u603b\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 hasPathSum(self, root: Optional&#91;TreeNode], targetSum: int) -> bool:\r\n        def subisBalanced(root,deep,target):\r\n            if root.left!=None:\r\n                deepl=deep+root.left.val\r\n                if subisBalanced(root.left,deepl,target):\r\n                    return True            \r\n            if  root.right!=None:\r\n                deepr=deep+root.right.val \r\n                if subisBalanced(root.right,deepr,target):\r\n                    return True\r\n            \r\n            if  root.left==None and root.right==None and deep==target:    \r\n                return True\r\n        if root==None:\r\n            return False\r\n        else:\r\n            if subisBalanced(root,root.val,targetSum)==True:\r\n                return True\r\n            else:\r\n                return False\r\n\r\n# @lc code=end<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-style-default\"><img loading=\"lazy\" width=\"875\" height=\"215\" src=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-311.png\" alt=\"\" class=\"wp-image-2487\" srcset=\"http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-311.png 875w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-311-300x74.png 300w, http:\/\/139.9.1.231\/wp-content\/uploads\/2022\/01\/image-311-768x189.png 768w\" sizes=\"(max-width: 875px) 100vw, 875px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u7ed9\u4f60\u4e8c\u53c9\u6811\u7684\u6839\u8282\u70b9&nbsp;root&nbsp;\u548c\u4e00\u4e2a\u8868\u793a\u76ee\u6807\u548c\u7684\u6574\u6570&nbsp;targetSum&#038;nbs &hellip; <a href=\"http:\/\/139.9.1.231\/index.php\/2022\/01\/29\/leetcodeday112\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">leetcodeday112&#8211;\u8def\u5f84\u603b\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\/2486"}],"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=2486"}],"version-history":[{"count":1,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2486\/revisions"}],"predecessor-version":[{"id":2488,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/posts\/2486\/revisions\/2488"}],"wp:attachment":[{"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/media?parent=2486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/categories?post=2486"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.9.1.231\/index.php\/wp-json\/wp\/v2\/tags?post=2486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}