# Why is the output of "{1, 2}, 1" is false?

• ``````   1
``````

2 *

The struct is like above, and the sum of right path is 1. Why the output is false?

Additional:

Find another problem: the output of "{1}, 1" is true......

why.....

• the question is "determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum". So the condition is there is a path from the root to a leaf. For your tree, there is only one leaf (2)

• the key is:

``````if (node->left == NULL && node -> right == NULL)
node is leaf;
else
node is not leaf;
``````

so 1 is not leaf

maybe this example is more clear:

{1, 2, 3, 4}, 3 is false, just two path: 1 -> 2 -> 4 or 1 -> 3, but 1 -> 2 is not

• Definition of leaf: node that has no children.
That confused me for a while also.
Cheers!

• Have the same question. Now, figure out the exactly meaning "the node without children is leaf".

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.