C++, DFS using unordered_map clean solution
class Solution {\npublic:\n    \n    unordered_mapm;\n    \n    int func(TreeNode root) {\n        \n        if(!root) return 0;\n        \n        int child=0,
class Solution {\npublic:\n    \n    unordered_map<TreeNode*, int>m;\n    \n    int func(TreeNode* root) {\n        \n        if(!root) return 0;\n        \n        int child=0, grandchild=0;\n        \n        child = func(root->left);\n        child += func(root->right);\n        \n        if(root->left)\n        {\n            grandchild = m[root->left->left];\n            grandchild += m[root->left->right];\n        }\n        if(root->right)\n        {\n            grandchild += m[root->right->left];\n            grandchild += m[root->right->right];\n        }    \n        \n        m[root] = max(root->val + grandchild , child);    \n        return m[root];        \n    }\n    \n    int rob(TreeNode* root) {\n        \n        m.clear();\n        if(!root)\n            return 0;\n        \n        return func(root);\n    }\n};
['C++']