JavaScript with explaination
As most of the tree problems, recurssion is the easiest way to start.\nThen, we need to figure out what we want to get from each of the node.\nWe want to know t
As most of the tree problems, recurssion is the easiest way to start.\nThen, we need to figure out what we want to get from each of the node.\nWe want to know the max value we can get if we rob it or not, `[rob, not]`.\nIf the node is a leaf, it\'s `[0,0]`,\nif it\'s not a leaf:\n1. if we rob it, then we can\'t rob its leaves.\n2. if we do not rob it, then we need to find the max from the combinations of the leaves. \n\n```\nvar rob = function(root) {\n    function helper(node){\n        if(!node) return [0,0];\n        const [lr,ln] = helper(node.left);\n        const [rr, rn] = helper(node.right);\n        return [node.val + ln + rn, Math.max(lr+rr, ln+rn, lr+rn, ln+rr)];\n    }\n    \n    return Math.max(...helper(root));\n};\n```
['Dynamic Programming', 'JavaScript']