My simple Java recursive solution
public class Solution {\n        public int rob(TreeNode root) {\n            if(root==null) return 0;\n            if(root.left==null&&root.right==null) return
    public class Solution {\n        public int rob(TreeNode root) {\n            if(root==null) return 0;\n            if(root.left==null&&root.right==null) return root.val;\n            \n            int left=0, right=0;\n            int subleft=0, subright=0;\n        \n        if(root.left!=null){\n            left=rob(root.left);\n            subleft=rob(root.left.left)+rob(root.left.right);\n        }\n        \n        if(root.right!=null){\n            right=rob(root.right);\n            subright=rob(root.right.left)+rob(root.right.right);\n        }\n        \n        int sum1=left+right;\n        int sum2=subleft+subright+root.val;\n        \n        return (sum1>sum2)?sum1:sum2;\n    }\n}
[]