👏🏻 Python Stack | DFS - 公瑾™
144. Binary Tree Preorder Traversal\n\n> \u7C7B\u578B\uFF1ADFS Stack | Recursive\n> Time Complexity O(n)\n> Space Complexity O(1)\n\n\n#### DFS Recursive\npytho
### 144. Binary Tree Preorder Traversal\n```\n> \u7C7B\u578B\uFF1ADFS Stack | Recursive\n> Time Complexity O(n)\n> Space Complexity O(1)\n```\n\n#### DFS Recursive\n```python\nclass Solution(object):\n    def preorderTraversal(self, root):\n        self.res = []\n        self.dfs(root)\n        return self.res\n    \n    def dfs(self, root):\n        if not root:\n            return \n        self.res.append(root.val)\n        self.dfs(root.left)\n        self.dfs(root.right)     \n```\n\n#### Stack\n```python\nclass Solution(object):\n    def preorderTraversal(self, root):\n        res = []\n        stack = [root]\n        while stack:\n            node = stack.pop()\n            if node:\n                res.append(node.val)\n                stack.append(node.right)\n                stack.append(node.left)\n        return res\n```
[]