mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
40 lines
1.5 KiB
HTML
40 lines
1.5 KiB
HTML
<p>给你二叉树的根结点 <code>root</code> ,此外树的每个结点的值要么是 <code>0</code> ,要么是 <code>1</code> 。</p>
|
||
|
||
<p>返回移除了所有不包含 <code>1</code> 的子树的原二叉树。</p>
|
||
|
||
<p>节点 <code>node</code> 的子树为 <code>node</code> 本身加上所有 <code>node</code> 的后代。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/04/06/1028_2.png" style="width: 500px; height: 140px;" />
|
||
<pre>
|
||
<strong>输入:</strong>root = [1,null,0,0,1]
|
||
<strong>输出:</strong>[1,null,0,null,1]
|
||
<strong>解释:</strong>
|
||
只有红色节点满足条件“所有不包含 1 的子树”。 右图为返回的答案。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/04/06/1028_1.png" style="width: 500px; height: 115px;" />
|
||
<pre>
|
||
<strong>输入:</strong>root = [1,0,1,0,0,0,1]
|
||
<strong>输出:</strong>[1,null,1,null,1]
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/04/05/1028.png" style="width: 500px; height: 134px;" />
|
||
<pre>
|
||
<strong>输入:</strong>root = [1,1,0,1,1,0,1,0]
|
||
<strong>输出:</strong>[1,1,0,1,1,null,1]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li>树中节点的数目在范围 <code>[1, 200]</code> 内</li>
|
||
<li><code>Node.val</code> 为 <code>0</code> 或 <code>1</code></li>
|
||
</ul>
|