mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
37 lines
1.5 KiB
HTML
37 lines
1.5 KiB
HTML
<p>给定一个二叉树的根节点 <code>root</code> ,和一个整数 <code>targetSum</code> ,求该二叉树里节点值之和等于 <code>targetSum</code> 的 <strong>路径</strong> 的数目。</p>
|
||
|
||
<p><strong>路径</strong> 不需要从根节点开始,也不需要在叶子节点结束,但是路径方向必须是向下的(只能从父节点到子节点)。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<p><img src="https://assets.leetcode.com/uploads/2021/04/09/pathsum3-1-tree.jpg" style="width: 452px; " /></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>root = [10,5,-3,3,2,null,11,3,-2,null,1], targetSum = 8
|
||
<strong>输出:</strong>3
|
||
<strong>解释:</strong>和等于 8 的路径有 3 条,如图所示。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>root = [5,4,8,11,null,13,4,7,2,null,null,5,1], targetSum = 22
|
||
<strong>输出:</strong>3
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li>二叉树的节点个数的范围是 <code>[0,1000]</code></li>
|
||
<li><meta charset="UTF-8" /><code>-10<sup><span style="font-size: 9.449999809265137px;">9</span></sup> <= Node.val <= 10<sup><span style="font-size: 9.449999809265137px;">9</span></sup></code> </li>
|
||
<li><code>-1000 <= targetSum <= 1000</code> </li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p><meta charset="UTF-8" />注意:本题与主站 437 题相同:<a href="https://leetcode-cn.com/problems/path-sum-iii/">https://leetcode-cn.com/problems/path-sum-iii/</a></p>
|