Easy understanding solution with dfs
dfs all the nodes of the tree, each node return two number, int[] num, num[0] is the max value while rob this node, num[1] is max value while not rob this value
dfs all the nodes of the tree, each node return two number, int[] num, num[0] is the max value while rob this node, num[1] is max value while not rob this value. Current node return value only depend on its children's value. Transform function should be very easy to understand.\n\n    public class Solution {\n        public int rob(TreeNode root) {\n            int[] num = dfs(root);\n            return Math.max(num[0], num[1]);\n        }\n        private int[] dfs(TreeNode x) {\n            if (x == null) return new int[2];\n            int[] left = dfs(x.left);\n            int[] right = dfs(x.right);\n            int[] res = new int[2];\n            res[0] = left[1] + right[1] + x.val;\n            res[1] = Math.max(left[0], left[1]) + Math.max(right[0], right[1]);\n            return res;\n        }\n    }
['Java']