House Robber III LeetCode solution in JavaScript
1var rob = function (root) {2const dfs = (node = root) => {3if (!node || node.val === null) return [0, 0];4const { val, left, right } = node;5const [robL, notRobL] = dfs(left);6const [robR, notRobR] = dfs(right);7const rob = val + notRobL + notRobR;8const notRob = Math.max(robL, notRobL) + Math.max(robR, notRobR);910return [rob, notRob];11};1213return Math.max(...dfs());14};