✅ Simplest solution ever on Dynamic Programming
/\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode() : val(0), left
/**\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    unordered_map<TreeNode*, int> map;\n   \n    int rob(TreeNode* root) {\n        \n        if(root==NULL) return 0;\n        \n        if(map.count(root)) return map[root];\n        \n        int sum=0;\n        \n        if(root->left)\n            sum+=rob(root->left->left)+rob(root->left->right);\n        if(root->right)\n            sum+=rob(root->right->left)+rob(root->right->right);\n        \n        return map[root]=max(root->val+sum,rob(root->left)+rob(root->right));       \n    }\n};\n\n\n
['Dynamic Programming', 'C', 'C++']