code: def has_path_sum2(root, sum):
      if root is None:
          return False
      stack = [(root, root.val)]
      while stack:
          node, val = stack.pop()
          if node.left is None and node.right is None:
              if val == sum:
                  return True
          if node.left is not None:
              stack.append((node.left, val + node.left.val))
          if node.right is not None:
              stack.append((node.right, val + node.right.val))
      return False
  
label_desc: Use image node_id 2 for calling a global function with example usage: has_path_sum2(root, sum) and returns: False, False, True