-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.txt
1 lines (1 loc) · 1.72 KB
/
info.txt
1
{"id":724669109,"lang":"cpp","lang_name":"C++","time":"6 months, 1 week","timestamp":1655495738,"status":10,"status_display":"Accepted","runtime":"10 ms","url":"/submissions/detail/724669109/","is_pending":"Not Pending","title":"Binary Tree Cameras","memory":"21.3 MB","code":"/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n int ans;\n int solve(TreeNode * root){\n if(!root->left && !root->right){\n root->val = 1;\n return 0;\n }\n int res = 0;\n int l = 2, r = 2;\n if(root->left){\n res = res + solve(root->left);\n l = root->left->val;\n }\n if(root->right){\n res = res + solve(root->right);\n r = root->right->val;\n }\n \n if(l==1 || r==1){\n root->val = 3;\n return res + 1;\n }\n \n if(l==3 || r==3){\n root->val = 2;\n return res;\n }\n root->val = 1;\n return res;\n }\n int minCameraCover(TreeNode* root) {\n int ans = solve(root);\n return root->val==1?ans+1:ans;\n }\n};","compare_result":"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111","title_slug":"binary-tree-cameras","has_notes":false,"notes":"","topic_tags":[]}