recursive approach + memoization
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:n\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\ndef fun(flg,root,memo):\n    if(root==None):\n        return 0\n    if((root,flg) in memo):\n        return memo[(root,flg)]\n    if(flg==1):\n        a=fun(0,root.left,memo)+fun(0,root.right,memo)\n        memo[(root,flg)]=a\n        return a\n    a=fun(0,root.left,memo)+fun(0,root.right,memo)\n    b=fun(1,root.left,memo)+fun(1,root.right,memo)+root.val\n    x=max(a,b)\n    memo[(root,flg)]=x\n    return x\nclass Solution:\n    def rob(self, root: Optional[TreeNode]) -> int:\n        memo={}\n        return(fun(0,root,memo))\n```
['Recursion', 'Python', 'Python3']