class Solution:
    def preorderTraversal(self , root: TreeNode) -> List[int]:
        ans=[]
        def preorder(root):
            if not root: return 
            ans.append(root.val)
            if root.left:
                preorder(root.left)
            if root.right:
                preorder(root.right)
        preorder(root)
        return ans