Tree: Depth-First Search - Path Sum
Consider the following Python function intended to check if a binary tree has a root-to-leaf path with sum equal to
Which statement best describes the issue?
targetSum. Identify the logical error in the code snippet below:def hasPathSum(root, targetSum):
if root is None:
return False
if root.left is None and root.right is None:
return root.val == targetSum
return hasPathSum(root.left, targetSum - root.val) or hasPathSum(root.right, targetSum - root.val)
Which statement best describes the issue?
