Simple iterative and recursive solutions
\nSolution 1, Iterative\n\n    def preorderTraversal(self, root):\n        stack, ans =[root], []\n        while stack:\n            node = stack.pop(-1)\n     
\n**Solution 1, Iterative**\n\n    def preorderTraversal(self, root):\n        stack, ans =[root], []\n        while stack:\n            node = stack.pop(-1)\n            while node:\n                if node.right:\n                    stack.append(node.right)\n                ans.append(node.val)\n                node=node.left\n        return ans\n\n<br><br>\n\n**Solution 2 , Recursive**\n\n    def preorderTraversal(self, root):\n        def DFS(node):\n            if node:\n                ans.append(node.val)\n                DFS(node.left)\n                DFS(node.right)\n        ans = []\n        DFS(root)\n        return ans
['Python']