每日一题力扣94 二叉树的中序遍历

时间:2021-04-15 12:16:15   收藏:0   阅读:0

 

给定一个二叉树的根节点 root ,返回它的 中序 遍历。

 

示例 1:

技术图片

输入:root = [1,null,2,3]
输出:[1,3,2]

 

class Solution:
    def inorderTraversal(self, root: TreeNode) -> List[int]:
        def in_order(t):
            if not t:
                return 
            in_order(t.left)
            res.append(t.val)
            in_order(t.right)
        res=[]
        in_order(root)
        return res

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!