class Solution:
def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:
def isornot(root,targetSum):
if not root.left and not root.right and targetSum==0:
return True
if not root.left and not root.right:
return False
if root.left:
targetSum -= root.left.val
if isornot(root.left,targetSum): return True
targetSum += root.left.val
if root.right:
targetSum -= root.right.val
if isornot(root.right,targetSum): return True
targetSum -= root.right.val
return False
return isornot(root,targetSum-root.val) if root else False