Python recursive and iterative solutions
Please see and vote for my solutions for these similar problems.\n94. Binary Tree Inorder Traversal\n144. Binary Tree Preorder Traversal\n145. Binary Tree Posto
Please see and vote for my solutions for these similar problems.\n[94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/discuss/332283/Python-recursive-and-iterative-solutions)\n[144. Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/discuss/332277/Python-recursive-and-iterative-solutions)\n[145. Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/discuss/332286/Python-recursive-and-iterative-solutions)\n\nRecursive solution:\n```\n    def preorderTraversal(self, root: TreeNode) -> List[int]:\n        def dfs(node):\n            if not node:\n                return\n            pre_order.append(node.val)\n            dfs(node.left)\n            dfs(node.right)\n        \n        pre_order = []\n        dfs(root)\n        return pre_order\n```\n\nIterative solution:\n```\n    def preorderTraversal(self, root: TreeNode) -> List[int]:\n        if not root:\n            return []\n        pre_order = []\n        stack = [root]\n        while stack:\n            top = stack.pop()\n            pre_order.append(top.val)\n            if top.right:\n                stack.append(top.right)\n            if top.left:\n                stack.append(top.left)\n        return pre_order\n```
[]