2018-12-06 leetcode House Robber III House Robber IIIDFS 版本 123456789101112131415161718# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def rob(self, root): """ :type root: TreeNode :rtype: int """ def dfs(node): if not node: return 0, 0 l, r = dfs(node.left), dfs(node.right) return max(l) + max(r), node.val + l[0] + r[0] return max(dfs(root)) leet code Newer Diameter of Binary Tree Older Convert BST to Greater Tree