mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
25 lines
797 B
HTML
25 lines
797 B
HTML
|
<p>给定一棵二叉树,其中每个节点都含有一个整数数值(该值或正或负)。设计一个算法,打印节点数值总和等于某个给定值的所有路径的数量。注意,路径不一定非得从二叉树的根节点或叶节点开始或结束,但是其方向必须向下(只能从父节点指向子节点方向)。</p>
|
|||
|
|
|||
|
<p><strong>示例:</strong><br>
|
|||
|
给定如下二叉树,以及目标和 <code>sum = 22</code>,</p>
|
|||
|
|
|||
|
<pre> 5
|
|||
|
/ \
|
|||
|
4 8
|
|||
|
/ / \
|
|||
|
11 13 4
|
|||
|
/ \ / \
|
|||
|
7 2 5 1
|
|||
|
</pre>
|
|||
|
|
|||
|
<p>返回:</p>
|
|||
|
|
|||
|
<pre>3
|
|||
|
<strong>解释:</strong>和为 22 的路径有:[5,4,11,2], [5,8,4,5], [4,11,7]</pre>
|
|||
|
|
|||
|
<p>提示:</p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>节点总数 <= 10000</code></li>
|
|||
|
</ul>
|