337. House Robber III
题目描述
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the “root.” Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that “all houses in this place forms a binary tree”. It will automatically contact the police if two directly-linked houses were broken into on the same night.
Determine the maximum amount of money the thief can rob tonight without alerting the police.
题目大意
小偷又找到了新的目标,这条街上的房子呈二叉树排列,同一晚上相邻的两层被偷会引发警报。
解题思路
递归,深度优先搜索(DFS
当遍历到某一层时,偷当前层和不偷的最大值。
代码
|
|