mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 19:01:47 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,33 +1,42 @@
|
||||
「力扣嘉年华」的中心广场放置了一个巨型的二叉树形状的装饰树。每个节点上均有一盏灯和三个开关。节点值为 `0` 表示灯处于「关闭」状态,节点值为 `1` 表示灯处于「开启」状态。每个节点上的三个开关各自功能如下:
|
||||
- 开关 `1`:切换当前节点的灯的状态;
|
||||
- 开关 `2`:切换 **以当前节点为根** 的子树中,所有节点上的灯的状态,;
|
||||
- 开关 `3`:切换 **当前节点及其左右子节点**(若存在的话) 上的灯的状态;
|
||||
<p>「力扣嘉年华」的中心广场放置了一个巨型的二叉树形状的装饰树。每个节点上均有一盏灯和三个开关。节点值为 <code>0</code> 表示灯处于「关闭」状态,节点值为 <code>1</code> 表示灯处于「开启」状态。每个节点上的三个开关各自功能如下:</p>
|
||||
|
||||
给定该装饰的初始状态 `root`,请返回最少需要操作多少次开关,可以关闭所有节点的灯。
|
||||
<ul>
|
||||
<li>开关 <code>1</code>:切换当前节点的灯的状态;</li>
|
||||
<li>开关 <code>2</code>:切换 <strong>以当前节点为根</strong> 的子树中,所有节点上的灯的状态;</li>
|
||||
<li>开关 <code>3</code>:切换 <strong>当前节点及其左右子节点</strong>(若存在的话) 上的灯的状态;</li>
|
||||
</ul>
|
||||
|
||||
**示例 1:**
|
||||
>输入:`root = [1,1,0,null,null,null,1]`
|
||||
>
|
||||
>输出:`2`
|
||||
>
|
||||
>解释:以下是最佳的方案之一,如图所示
|
||||
{:width="300px"}
|
||||
<p>给定该装饰的初始状态 <code>root</code>,请返回最少需要操作多少次开关,可以关闭所有节点的灯。</p>
|
||||
|
||||
**示例 2:**
|
||||
>输入:`root = [1,1,1,1,null,null,1]`
|
||||
>
|
||||
>输出:`1`
|
||||
>
|
||||
>解释:以下是最佳的方案,如图所示
|
||||
{:width="300px"}
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
**示例 3:**
|
||||
>输入:`root = [0,null,0]`
|
||||
>
|
||||
>输出:`0`
|
||||
>
|
||||
>解释:无需操作开关,当前所有节点上的灯均已关闭
|
||||
<pre>
|
||||
<strong>输入:</strong>root = [1,1,0,null,null,null,1]
|
||||
<strong>输出:</strong>2
|
||||
<strong>解释:</strong>以下是最佳的方案之一,如图所示
|
||||
<img alt="" src="https://pic.leetcode-cn.com/1629357030-GSbzpY-b71b95bf405e3b223e00b2820a062ba4.gif" style="width: 300px; height: 225px;" />
|
||||
</pre>
|
||||
|
||||
**提示:**
|
||||
- `1 <= 节点个数 <= 10^5`
|
||||
- `0 <= Node.val <= 1`
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>root = [1,1,1,1,null,null,1]
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>以下是最佳的方案,如图所示
|
||||
<img alt="" src="https://pic.leetcode-cn.com/1629356950-HZsKZC-a4091b6448a0089b4d9e8f0390ff9ac6.gif" style="width: 300px; height: 225px;" />
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>root = [0,null,0]
|
||||
<strong>输出:</strong>0
|
||||
<strong>解释:</strong>无需操作开关,当前所有节点上的灯均已关闭
|
||||
</pre>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= 节点个数 <= 10^5</code></li>
|
||||
<li><code>0 <= Node.val <= 1</code></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user