LeetCode No.94 Posted on 2021-04-26 | In OJ , LeetCode | | LeetCode第九十四题—二叉树的中序遍历 ¶题目描述 给定一个二叉树的根节点 root ,返回它的 中序 遍历。 123456789101112示例 1:输入:root = [1,null,2,3]输出:[1,3,2]示例 2:输入:root = []输出:[]示例 3:输入:root = [1]输出:[1] 1234示例 4:输入:root = [1,2]输出:[2,1] 123456789示例 5:输入:root = [1,null,2]输出:[1,2] 提示:树中节点数目在范围 [0, 100] 内-100 <= Node.val <= 100 ¶代码 123456789101112131415161718class Solution(object): def inorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] 核心思想: 中序遍历原理:先遍历左子树,在访问根节点,最后遍历右子树 """ self.res = [] def middle_order(node): if node != None: middle_order(node.left) self.res.append(node.val) middle_order(node.right) middle_order(root) return self.res Hobby lead creation, technology change world. Post author: StriveZs Post link: www.strivezs.com/2021/04/26/LeetCode%E7%AC%AC%E4%B9%9D%E5%8D%81%E5%9B%9B%E9%A2%98/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.