inorder_transversal.py 418 B

12345678910111213
  1. class TreeNode:
  2. def __init__(self, val=0, left=None, right=None):
  3. self.val = val
  4. self.left = left
  5. self.right = right
  6. class Solution:
  7. def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
  8. if root == None:
  9. return []
  10. left = self.inorderTraversal(root.left)
  11. right = self.inorderTraversal(root.right)
  12. return left + [root.val] + right