# 337. House Robber III!

```java
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public int rob(TreeNode root) {
        int[] result = dfs(root);
        return Math.max(result[0], result[1]);
    }
    
    private int[] dfs(TreeNode node){
        if(node == null) return new int[]{0,0};
    
        int[] preLeft = dfs(node.left);
        int[] preRight = dfs(node.right);
        
        int nodeNotInclude = Math.max(preLeft[0], preLeft[1]) + Math.max(preRight[0], preRight[1]);
        int nodeInclude = node.val+preLeft[1]+preRight[1];
        
        return new int[]{nodeInclude, nodeNotInclude};
    }
}
```
