package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
type TreeNode = structures.TreeNode
func rob337(root *TreeNode) int {
a, b := dfsTreeRob(root)
return max(a, b)
}
func dfsTreeRob(root *TreeNode) (a, b int) {
if root == nil {
return 0, 0
}
l0, l1 := dfsTreeRob(root.Left)
r0, r1 := dfsTreeRob(root.Right)
tmp0 := max(l0, l1) + max(r0, r1)
tmp1 := root.Val + l0 + r0
return tmp0, tmp1
}
func max(a int, b int) int {
if a > b {
return a
}
return b
}