We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c84da80 commit 5bbdeffCopy full SHA for 5bbdeff
968-binary-tree-cameras.js
@@ -0,0 +1,27 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val) {
4
+ * this.val = val;
5
+ * this.left = this.right = null;
6
+ * }
7
+ */
8
9
+ * @param {TreeNode} root
10
+ * @return {number}
11
12
+const minCameraCover = function(root) {
13
+ if (root === null) return 0;
14
+ let max = 0;
15
+ return (helper(root) < 1 ? 1 : 0) + max;
16
+ function helper(root) {
17
+ if (root === null) return 2;
18
+ if (root.left === null && root.right === null) return 0;
19
+ let left = helper(root.left);
20
+ let right = helper(root.right);
21
+ if (left === 0 || right === 0) {
22
+ max++;
23
+ return 1;
24
+ }
25
+ return left === 1 || right === 1 ? 2 : 0;
26
27
+};
0 commit comments