Java simple recursive solution with explanation.
We can think in terms of the choices the robber has to make at every node.\n\n\n    public int rob(TreeNode root) {\n        return rob(root, false);\n    }\n\n
We can think in terms of the choices the robber has to make at every node.\n\n```\n    public int rob(TreeNode root) {\n        return rob(root, false);\n    }\n\n    public int rob(TreeNode root, boolean isParentRobbed) {\n\n        if (root == null) {\n            return 0;\n        }\n\n        // if the parent house is robbed, the current house CANNOT be robbed\n        if (isParentRobbed) {\n            return rob(root.left, false) + rob(root.right, false);\n        }\n\n        // the robber has two options\n        // 1. DO NOT rob the current house\n        // 2. rob the current house\n        // we need the maximum profit of the two choices\n        return Math.max(rob(root.left, false) + rob(root.right, false), // DON\'T rob\n                root.val + rob(root.left, true) + rob(root.right, true)); // rob\n\n    }\n\n```
['Recursion', 'Java']