# Leetcode 968 - Binary tree cams

`Note:`

`DP`

`dp[0]`

node has a cam.`dp[1]`

children have cams.`dp[2]`

parent has cams.- Assume both left and right subtree exist.
`dp[0]`

: It doesn’t matter children have cams or not. So we need to pick min cams from them.`dp[1]`

: Consider`left`

&`right`

separately. Assume`left`

has a cam, then pick min from`right[1]`

or`right[0]`

.`dp[2]`

: When cur node’s parent has a cam. For left or right subtree, two situations for each: A cam for themself or covered by children.

`Question:`

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.

`Code:`

1 | /** |