leetcode刷题-94二叉树的中序遍历
题目
给定一个二叉树,返回它的中序 遍历。
实现
# def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: def inorderTraversal(self, root: TreeNode) -> List[int]: result = [] def inorder(tree, result): if tree != None: if tree.left != None: inorder(tree.left, result) result.append(tree.val) if tree.right != None: inorder(tree.right, result) inorder(root, result) return result