def path_sum(root, target_sum):
    """
    Given a binary tree and a sum, determine if the tree has
    a root-to-leaf path such that adding up all the values along
    the path equals the given sum.
    """

    def is_leaf(node):
        return node.left is None and node.right is None

    def leaf_nodes(node, parent_path_sum):
        if node is None:
            return

        new_sum = parent_path_sum + node.val
        if is_leaf(node):
            yield (node, new_sum)

        for n in leaf_nodes(node.left, new_sum):
            yield n

        for n in leaf_nodes(node.right, new_sum):
            yield n

    for node, path_sum in leaf_nodes(root, 0):
        if path_sum == target_sum:
            return True

    return False