"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""classSolution:""" @param root: The root of binary tree. @return: Preorder in ArrayList which contains node values. """defpreorder(self,node,result):result.append(node.val)ifnode.left!=None:self.preorder(node.left,result)ifnode.right!=None:self.preorder(node.right,result)returnresultdefpreorderTraversal(self,root):# write your code hereresult=[]ifroot==None:returnresultself.preorder(root,result)returnresult