# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution(object):
def foo(self, node, result):
if node:
result.append(node.val)
if node.left:
self.foo(node.left, result)
if node.right:
self.foo(node.right, result)
return result
def preorderTraversal(self, root):
"""
:type root: TreeNode
:rtype: List[int]
"""
return self.foo(root, [])