root of a binary tree and an integer total. Return True if some path from the root down to a leaf has node values adding up to exactly total, and False otherwise.
A leaf is a node with no children. The path must start at the root and end at a leaf; it cannot stop halfway.root=tree_node([3, 9, -2, None, None, 4, 6]), total=7 → True
The path 3 → -2 → 6 adds up to 7, and 6 is a leaf.
root=tree_node([2, 5]), total=2 → False
The root 2 is not a leaf because it has the child 5. The only root-to-leaf path 2 → 5 sums to 7.
root=tree_node([]), total=0 → False
An empty tree has no paths at all.
root=tree_node([3, 9, -2, None, None, 4, 6]), total=7
True
Run checks the first 3 tests in your browser. Submit checks all 78 tests on the server, hidden ones included.