easy recursive solution in c++
Intuition\n Describe your first thoughts on how to solve this problem. \nwe have to find the max sum possible of all the non adjacent values in the tree\n# Appr
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe have to find the max sum possible of all the non adjacent values in the tree\n# Approach\n<!-- Describe your approach to solving the problem. -->\nto do this we will use recursion and store two piece of values one will be the sum if that node is used and one if that node is not used.\nif that node is used then we cant take the values of its child so we will add the values when its chil node is not used. when that node is not considered then we can either take its child node or not so we will store the max of the both case. answer will be max of both the values.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    pair<int,int> solve(TreeNode* root){\n        if(root == NULL){\n            return {0,0};\n        }\n\n        pair<int,int> left = solve(root->left);\n        pair<int,int> right = solve(root->right);\n\n        pair<int,int> temp;\n        temp.first = root->val + left.second + right.second;\n        temp.second = max(left.first,left.second) + max(right.first,right.second);\n\n        return temp;\n    }\n\n    int rob(TreeNode* root) {\n        pair<int,int> ans = solve(root);\n        return max(ans.first,ans.second);\n    }\n};\n```
['Tree', 'Recursion', 'Binary Tree', 'C++']