Class Solution

java.lang.Object
g0901_1000.s0968_binary_tree_cameras.Solution

public class Solution extends Object
968 - Binary Tree Cameras.<p>Hard</p> <p>You are given the <code>root</code> of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children.</p> <p>Return <em>the minimum number of cameras needed to monitor all nodes of the tree</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2018/12/29/bst_cameras_01.png" alt="" /></p> <p><strong>Input:</strong> root = [0,0,null,0,0]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> One camera is enough to monitor all nodes if placed as shown.</p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2018/12/29/bst_cameras_02.png" alt="" /></p> <p><strong>Input:</strong> root = [0,0,null,0,null,0,null,null,0]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in the tree is in the range <code>[1, 1000]</code>.</li> <li><code>Node.val == 0</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minCameraCover

      public int minCameraCover(TreeNode root)