Java clean solution with recursion and map as cache
```\n    private Map map = new HashMap<>();\n    \n    public int rob(TreeNode root) {\n        if (map.containsKey(root)) {\n            return map.get(root);\
```\n    private Map<TreeNode, Integer> map = new HashMap<>();\n    \n    public int rob(TreeNode root) {\n        if (map.containsKey(root)) {\n            return map.get(root);\n        }\n        \n        int result = Math.max(robFrom(root), robNext(root));\n        map.put(root, result);\n        return result;\n    }\n    \n    private int robFrom(TreeNode node) {\n        if (node == null) {\n            return 0;\n        }\n        \n        return node.val + robNext(node.left) + robNext(node.right);\n    }\n    \n    private int robNext(TreeNode node) {\n        if (node == null) {\n            return 0;\n        }\n        \n        return rob(node.left) + rob(node.right);\n    }\n}
[]