题目:
题解:
class Solution:def hasPathSum(self, root: TreeNode, sum: int) -> bool:if not root:return Falseif not root.left and not root.right:return sum == root.valreturn self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val)