Python 3 iterative and recursive solution
\n# the value in the couple is (yesrob, norob)\n# yesrob is the max amount with robbing the current node\n# norob is the max amount without robbing the current 
```\n# the value in the couple is (yesrob, norob)\n# yesrob is the max amount with robbing the current node\n# norob is the max amount without robbing the current node\nclass Solution_iterative_postorder:\n    def rob(self, root):\n        stack = [(0, root)]\n        d = {None: (0, 0)}\n        while stack:\n            seen, node = stack.pop()\n            if node is None:\n                continue\n            if not seen:\n                stack.extend([(1, node), (0, node.right), (0, node.left)])\n            else:\n                yesrob = d[node.left][1] + d[node.right][1] + node.val\n                norob = max(d[node.left]) + max(d[node.right])\n                d[node] = (yesrob, norob)\n        return max(d[root])\n\n\nclass Solution_recursive:\n    def rob(self, root):\n        """\n        :type root: TreeNode\n        :rtype: int\n        """\n        def couple(root):\n            if root is None:\n                return (0, 0)\n            left = couple(root.left)\n            right = couple(root.right)\n            return (left[1] + right[1] + root.val, max(left) + max(right))\n\n        return max(couple(root))\n```
[]