Skip to content

Commit cc8a783

Browse files
committed
Solution as on 25-06-2022 07:20 am
1 parent f266c68 commit cc8a783

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

0968. Binary Tree Cameras.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// 968.✅ Binary Tree Cameras
2+
3+
class Solution
4+
{
5+
public:
6+
int cam = 0;
7+
int minCameraCover(TreeNode *root)
8+
{
9+
if (Camera(root) == "Want")
10+
++cam;
11+
return cam;
12+
}
13+
14+
string Camera(TreeNode *root)
15+
{
16+
if (root == NULL)
17+
return "Ok";
18+
string left = Camera(root->left);
19+
string right = Camera(root->right);
20+
21+
if (left == "Want" || right == "Want")
22+
{
23+
++cam;
24+
return "Provide";
25+
}
26+
else if (left == "Provide" || right == "Provide")
27+
return "Ok";
28+
return "Want";
29+
}
30+
};

0 commit comments

Comments
 (0)