Z30
House Robber III (Tree)
Problem Statement & Objective
The thief has found himself a new place for his thievery again: a binary tree where houses are connected like tree nodes. No two directly-linked houses can be broken into.
Function Signature (Python)
house_robber_iii_tree(root: list) -> intInput & Output Contract
Output Rule:Maksimum para miktarı.
System Constraints
0 <= agac.length <= 10^4
0 <= agac[i] <= 10^4Example Execution Walkthrough
agac = [3, 2, 3, None, 3, None, 1]
3 (kök) + 3 + 1 = 7 (en iyi)
cevap: 7Example Test Scenarios (3)
Example 1
Input:
[[3,2,3,null,3,null,1]]Expected Output:
7Example 2: 4 + 5 = 9
Input:
[[3,4,5,1,3,null,1]]Expected Output:
9Example 3: Boş
Input:
[[]]Expected Output:
0