Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    968 - Binary Tree Cameras\.

    Hard

    You are given the root 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.

    Return the minimum number of cameras needed to monitor all nodes of the tree.

    Example 1:

    Input: root = 0,0,null,0,0

    Output: 1

    Explanation: One camera is enough to monitor all nodes if placed as shown.

    Example 2:

    Input: root = 0,0,null,0,null,0,null,null,0

    Output: 2

    Explanation: 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.

    Constraints:

    • The number of nodes in the tree is in the range [1, 1000].

    • Node.val == 0

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer minCameraCover(TreeNode root)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait