# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right classSolution: definorderTraversal(self, root: Optional[TreeNode]) -> List[int]: ans, stack = [], [] while root or stack: if root: stack.append(root) root = root.left else: root = stack.pop() ans.append(root.val) root = root.right return ans