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

 

posted @ 2020-08-14 10:20  maoguai  阅读(93)  评论(0编辑  收藏  举报