Tree/path_sum_in_tree library

🌳 Path Sum in Binary Tree

Checks if there exists a root-to-leaf path with a given sum. Returns true if such a path exists, false otherwise.

Time complexity: O(n) Space complexity: O(h)

Example:

final root = BinaryTreeNode<int>(5);
root.left = BinaryTreeNode<int>(4);
root.right = BinaryTreeNode<int>(8);
root.left!.left = BinaryTreeNode<int>(11);
final exists = hasPathSum(root, 20);
// exists: true

Functions

hasPathSum<T extends num>(BinaryTreeNode<T>? root, T sum) → bool