337. House Robber III
Practice House Robber III for free on NudgeCode: Medium, Binary Tree pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Houses are arranged as a binary tree, and each node holds the amount of money in that house. You cannot rob two houses that are directly connected (a parent and its child). Return the most money you can rob.
Example
root = [3,2,3,null,3,null,1] -> 7 (3 + 3 + 1)
root = [3,4,5,1,3,null,1] -> 9 (4 + 5)
Constraints
- 1 <= number of nodes <= 10^4
- 0 <= Node.val <= 10^4