Python solution
Recursive:\n\nclass Solution(object):\n    def preorderTraversal(self, root):\n        """\n        :type root: TreeNode\n        :rtype: List[int]\n        """
Recursive:\n```\nclass Solution(object):\n    def preorderTraversal(self, root):\n        """\n        :type root: TreeNode\n        :rtype: List[int]\n        """\n        if not root:\n            return []\n        elif not root.left and not root.right:\n            return [root.val]\n        l = self.preorderTraversal(root.left)\n        r = self.preorderTraversal(root.right)\n        return [root.val]+l+r\n```\nIterative:\n```\nclass Solution(object):\n    def preorderTraversal(self, root):\n        """\n        :type root: TreeNode\n        :rtype: List[int]\n        """\n        if not root:\n            return []\n        res = []\n        stack = [root]\n        while stack:\n            u = stack.pop()\n            res.append(u.val)\n            if u.right:\n                stack.append(u.right)\n            if u.left:\n                stack.append(u.left)\n        return res\n```\nAnother iterative solution:\n```\nclass Solution(object):\n    def preorderTraversal(self, root):\n        """\n        :type root: TreeNode\n        :rtype: List[int]\n        """\n        trav = root\n        stack = []\n        res = []\n        while trav or stack:\n            if trav:\n                stack.append(trav)\n                res.append(trav.val)\n                trav = trav.left\n            else:\n                u = stack.pop()\n                trav = u.right\n        return res\n```
[]