Tree: Depth-First Search - Path Sum
Examine the following buggy code for the Path Sum problem. Which line contains the subtle bug that causes incorrect results on some inputs?
def hasPathSum(root: Optional[TreeNode], targetSum: int) -> bool:
def dfs(node, curr_sum):
if not node:
return False
curr_sum += node.val
if curr_sum == targetSum: # Bug here
return True
return dfs(node.left, curr_sum) or dfs(node.right, curr_sum)
return dfs(root, 0)
