590: Time  94.11%, Solution with step by step explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n1. If the root is None, return an empty list.\n\n2. Initialize a stack ca
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. If the root is None, return an empty list.\n\n2. Initialize a stack called stack with the root node as its only element.\n\n3. Initialize an empty list called res to store the result.\n\n4. While the stack is not empty, pop the top element of the stack and append its value to the res list.\n\n5. For each child of the node, push the child onto the stack.\n\n6. Return the res list in reverse order using slicing.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def postorder(self, root: \'Node\') -> List[int]:\n        if not root:\n            return []\n        \n        stack = [root]\n        res = []\n        \n        while stack:\n            node = stack.pop()\n            res.append(node.val)\n            \n            for child in node.children:\n                stack.append(child)\n                \n        return res[::-1]\n\n```
['Stack', 'Tree', 'Depth-First Search', 'Python', 'Python3']