← 返回 bytedance 的题目列表House Robber III
类型:online_judge
In a binary tree, each node contains a positive integer value. A thief plans to rob houses (i.e., nodes) in the binary tree, but he cannot rob two directly connected houses. Calculate the maximum amount of money the thief can rob tonight.
Input Description:
A binary tree representing houses with a maximum of 1000 nodes.
Output Description:
Return an integer, the maximum amount of money.
Example:
Input:
{3, {2, null, 3}, {3, null, 1}}
Output:
7
Explanation: Rob houses 3 + 3 + 1.
Example
Input
root = TreeNode(3, TreeNode(2, None, TreeNode(3)), TreeNode(3, right=TreeNode(1)))