|
6 | 6 |
|
7 | 7 | <!-- 这里写题目描述 -->
|
8 | 8 |
|
9 |
| -<p>给定一棵二叉树的根 <code>root</code>,请你考虑它所有 <strong>从根到叶的路径</strong>:从根到任何叶的路径。(所谓一个叶子节点,就是一个没有子节点的节点)</p> |
| 9 | +<p>给你二叉树的根节点 <code>root</code> 和一个整数 <code>limit</code> ,请你同时删除树中所有 <strong>不足节点 </strong>,并返回最终二叉树的根节点。</p> |
10 | 10 |
|
11 |
| -<p>假如通过节点 <code>node</code> 的每种可能的 “根-叶” 路径上值的总和全都小于给定的 <code>limit</code>,则该节点被称之为「不足节点」,需要被删除。</p> |
| 11 | +<p>假如通过节点 <code>node</code> 的每种可能的 “根-叶” 路径上值的总和全都小于给定的 <code>limit</code>,则该节点被称之为<strong> 不足节点 </strong>,需要被删除。</p> |
12 | 12 |
|
13 |
| -<p>请你删除所有不足节点,并返回生成的二叉树的根。</p> |
| 13 | +<p><strong>叶子节点</strong>,就是没有子节点的节点。</p> |
14 | 14 |
|
15 | 15 | <p> </p>
|
16 | 16 |
|
17 |
| -<p><strong>示例 1:</strong></p> |
18 |
| - |
19 |
| -<pre><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-1.png" style="height: 200px; width: 482px;"> |
20 |
| -输入:</strong>root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1 |
21 |
| -<strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-2.png" style="height: 200px; width: 258px;"> |
22 |
| -输出:</strong>[1,2,3,4,null,null,7,8,9,null,14] |
| 17 | +<p><strong class="example">示例 1:</strong></p> |
| 18 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-11.png" style="width: 500px; height: 207px;" /> |
| 19 | +<pre> |
| 20 | +<strong>输入:</strong>root = [1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14], limit = 1 |
| 21 | +<strong>输出:</strong>[1,2,3,4,null,null,7,8,9,null,14] |
23 | 22 | </pre>
|
24 | 23 |
|
25 |
| -<p><strong>示例 2:</strong></p> |
26 |
| - |
27 |
| -<pre><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-3.png" style="height: 200px; width: 292px;"> |
28 |
| -输入:</strong>root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22 |
29 |
| -<strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-4.png" style="height: 200px; width: 264px;"> |
30 |
| -输出:</strong>[5,4,8,11,null,17,4,7,null,null,null,5]</pre> |
31 |
| - |
32 |
| -<p><strong>示例 3:</strong></p> |
| 24 | +<p><strong class="example">示例 2:</strong></p> |
| 25 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-3.png" style="width: 400px; height: 274px;" /> |
| 26 | +<pre> |
| 27 | +<strong>输入:</strong>root = [5,4,8,11,null,17,4,7,1,null,null,5,3], limit = 22 |
| 28 | +<strong>输出:</strong>[5,4,8,11,null,17,4,7,null,null,null,5] |
| 29 | +</pre> |
33 | 30 |
|
34 |
| -<pre><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/insufficient-5.png" style="height: 100px; width: 140px;"> |
35 |
| -输入:</strong>root = [5,-6,-6], limit = 0<strong> |
36 |
| -输出:</strong>[]</pre> |
| 31 | +<p><strong class="example">示例 3:</strong></p> |
| 32 | +<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/1000-1099/1080.Insufficient%20Nodes%20in%20Root%20to%20Leaf%20Paths/images/screen-shot-2019-06-11-at-83301-pm.png" style="width: 250px; height: 199px;" /> |
| 33 | +<pre> |
| 34 | +<strong>输入:</strong>root = [1,2,-3,-5,null,4,null], limit = -1 |
| 35 | +<strong>输出:</strong>[1,null,-3,4] |
| 36 | +</pre> |
37 | 37 |
|
38 | 38 | <p> </p>
|
39 | 39 |
|
40 | 40 | <p><strong>提示:</strong></p>
|
41 | 41 |
|
42 |
| -<ol> |
43 |
| - <li>给定的树有 <code>1</code> 到 <code>5000</code> 个节点</li> |
44 |
| - <li><code>-10^5 <= node.val <= 10^5</code></li> |
45 |
| - <li><code>-10^9 <= limit <= 10^9</code></li> |
46 |
| -</ol> |
| 42 | +<ul> |
| 43 | + <li>树中节点数目在范围 <code>[1, 5000]</code> 内</li> |
| 44 | + <li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li> |
| 45 | + <li><code>-10<sup>9</sup> <= limit <= 10<sup>9</sup></code></li> |
| 46 | +</ul> |
47 | 47 |
|
48 | 48 | <p> </p>
|
49 | 49 |
|
|
0 commit comments