Pregunta de entrevista de Atlassian

Root to path sum tree (both iterative and recursive)

Respuesta de la entrevista

Anónimo

10 de sept de 2021

def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool: if not root: return False elif not root.left and not root.right: return targetSum == root.val else: return self.hasPathSum(root.left, targetSum - root.val) or self.hasPathSum(root.right, targetSum - root.val)