JAVA | Simple and Easy Solution | Using pair Class
Do vote up if you like it :)\n\nclass Solution {\n    \n    class Pair{\n        int withRob;\n        int withoutRob;\n        \n        public Pair(int withRo
**Do vote up if you like it :)**\n```\nclass Solution {\n    \n    class Pair{\n        int withRob;\n        int withoutRob;\n        \n        public Pair(int withRob, int withoutRob){\n            this.withRob = withRob;\n            this.withoutRob = withoutRob;\n        }\n    }\n    \n    public int rob(TreeNode root) {\n         Pair obj = robHelper(root);\n         return Math.max(obj.withRob, obj.withoutRob);\n    }\n    \n    public Pair robHelper(TreeNode root){\n        if(root == null)\n            return new Pair(0, 0);\n        \n        Pair leftObj = robHelper(root.left);\n        Pair rightObj = robHelper(root.right);\n        \n        int withRob = leftObj.withoutRob + rightObj.withoutRob + root.val;\n        int withoutRob = Math.max(leftObj.withRob, leftObj.withoutRob) + Math.max(rightObj.withRob, rightObj.withoutRob);\n        \n        return new Pair(withRob, withoutRob);\n    }\n    \n}\n```
[]