天天看點

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