3 Simple Python solutions
Solution 1: Preorder traversal with stack\n\n\nclass Solution:\n    def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n        ans = []\n     
##### Solution 1: Preorder traversal with stack\n\n```\nclass Solution:\n    def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n        ans = []\n        stack = [root]\n        \n        while stack:\n            temp = stack.pop()\n            \n            if temp:\n                ans.append(temp.val)\n                stack.append(temp.right) #as we are using stack which works on LIFO, we need to push right tree first so that left will be popped out\n                stack.append(temp.left)\n                \n        return ans\n```\n\n\n##### Solution 2: With recursion for python beginners\n```\nclass Solution:\n    def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n        ans = []\n        if not root:\n            return ans\n        \n        def preorder(node):\n            if node:\n                ans.append(node.val)\n                preorder(node.left)\n                preorder(node.right)\n            \n        preorder(root)\n        return ans\n```\n\n##### Solution 3: Short solution\n```\nclass Solution:\n    def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:\n        if not root:\n            return []\n        \n        return [root.val] + self.preorderTraversal(root.left) + self.preorderTraversal(root.right)\n```
['Stack', 'Recursion', 'Python', 'Python3']