Skip to content

Commit 522655a

Browse files
committed
Runtime: 33 ms (Top 14.78%) | Memory: 23.8 MB (Top 20.27%)
1 parent 97f3343 commit 522655a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

scripts/algorithms/B/Binary Tree Cameras/Binary Tree Cameras.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1+
// Runtime: 33 ms (Top 14.78%) | Memory: 23.8 MB (Top 20.27%)
12
class Solution {
23
public:
34
map<TreeNode*, int> mpr;
45
int dp[1009][3];
5-
int minCameraCover(TreeNode* root)
6+
int minCameraCover(TreeNode* root)
67
{
78
int num = 0;
89
adres(root, num);
910
memset(dp, -1, sizeof(dp));
10-
11+
1112
int t1 = dp_fun(root, 0), t2 = dp_fun(root, 1), t3 = dp_fun(root, 2);
12-
13-
13+
1414
return min({t1, t3});
1515

1616
}
17-
17+
1818
int dp_fun(TreeNode* cur, int st)
1919
{
2020
int nd = mpr[cur];
@@ -26,7 +26,7 @@ class Solution {
2626
{
2727
return 1e8;
2828
}
29-
else
29+
else
3030
{
3131
return 0;
3232
}
@@ -39,14 +39,14 @@ class Solution {
3939
{
4040
dp[nd][st] = min({dp_fun(cur->left, 0) + dp_fun(cur->right, 0), dp_fun(cur->left, 0) + dp_fun(cur->right, 2), dp_fun(cur->left, 2) + dp_fun(cur->right, 0), dp_fun(cur->left, 2) + dp_fun(cur->right, 2)});
4141
}
42-
else
42+
else
4343
{
4444
dp[nd][st] = min({dp_fun(cur, 2), dp_fun(cur->left, 2) + dp_fun(cur->right, 0), dp_fun(cur->left, 0) + dp_fun(cur->right, 2), dp_fun(cur->left, 2) + dp_fun(cur->right, 2)});
4545
}
4646
}
4747
return dp[nd][st];
4848
}
49-
49+
5050
void adres(TreeNode* cur, int &cnt)
5151
{
5252
if(cur == NULL)
@@ -55,7 +55,7 @@ class Solution {
5555
}
5656
mpr[cur] = cnt;
5757
cnt++;
58-
58+
5959
adres(cur->left, cnt);
6060
adres(cur->right, cnt);
6161
}

0 commit comments

Comments
 (0)