```
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# @param {TreeNode} root
# @return {integer[]}
def preorderTraversal(self, root):
if not root:
return []
result, queue = [], [root]
while queue:
curNode = queue.pop()
if curNode:
result.append(curNode.val)
queue.append(curNode.right)
queue.append(curNode.left)
return result
```