天天看点

Leetcode | Path Sum I && II

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.

for example:

given the below binary tree

and <code>sum = 22</code>,

return true, as there exist a root-to-leaf

path <code>5-&gt;4-&gt;11-&gt;2</code> which sum is 22.

递归求解就可以。注意叶子结点条件是左右结点都为空。

given a binary tree and a sum, find all root-to-leaf paths where each path‘s

sum equals the given sum.

return