```
class Solution(object):
def preorderTraversal(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
if not root: return []
stack, res=[root], []
while stack:
node=stack.pop()
res+=[node.val]
if node.right: stack+=[node.right]
if node.left: stack+=[node.left]
return res
```