Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 65fae3b

Browse files
更新 0968.监控二叉树.md
CPP代码未语法高亮
1 parent 0edf01e commit 65fae3b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

‎problems/0968.监控二叉树.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171

7272
后序遍历代码如下:
7373

74-
```
74+
```CPP
7575
int traversal(TreeNode* cur) {
7676

7777
// 空节点,该节点有覆盖
@@ -124,7 +124,7 @@ int traversal(TreeNode* cur) {
124124
125125
代码如下:
126126
127-
```
127+
```CPP
128128
// 空节点,该节点有覆盖
129129
if (cur == NULL) return 2;
130130
```
@@ -143,7 +143,7 @@ if (cur == NULL) return 2;
143143

144144
代码如下:
145145

146-
```
146+
```CPP
147147
// 左右节点都有覆盖
148148
if (left == 2 && right == 2) return 0;
149149
```
@@ -163,7 +163,7 @@ left == 2 && right == 0 左节点覆盖,右节点无覆盖
163163
此时摄像头的数量要加一,并且return 1,代表中间节点放摄像头。
164164

165165
代码如下:
166-
```
166+
```CPP
167167
if (left == 0 || right == 0) {
168168
result++;
169169
return 1;
@@ -180,7 +180,7 @@ left == 1 && right == 1 左右节点都有摄像头
180180

181181
代码如下:
182182

183-
```
183+
```CPP
184184
if (left == 1 || right == 1) return 2;
185185
```
186186

@@ -198,7 +198,7 @@ if (left == 1 || right == 1) return 2;
198198

199199
所以递归结束之后,还要判断根节点,如果没有覆盖,result++,代码如下:
200200

201-
```
201+
```CPP
202202
int minCameraCover(TreeNode* root) {
203203
result = 0;
204204
if (traversal(root) == 0) { // root 无覆盖

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /