Binary Tree Cameras
Given a binary tree, we install cameras on the nodes of the tree.
Each camera at a node can monitorits parent, itself, and its immediate children.
Calculate the minimum number of cameras needed to monitor all nodes of the tree.
Example 1:

Example 2:

Note:
分析
3个状态NOT_MONITORED = 0
尽量往上放
1 2个儿子都被监视,求助parent
2任意儿子不被监视,本地放置 res++
3 直接返回被监视(可能儿子处放置
Last updated
Was this helpful?