94. 二叉树的中序遍历
1. 简介
链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
给定一个二叉树的根节点 root ,返回它的 中序 遍历。
示例 1:

1 | 输入:root = [1,null,2,3] |
示例 2:
1 | 输入:root = [] |
示例 3:
1 | 输入:root = [1] |
示例 4:

1 | 输入:root = [1,2] |
示例 5:

1 | 输入:root = [1,null,2] |
提示:
- 树中节点数目在范围
[0, 100]内 -100 <= Node.val <= 100
进阶: 递归算法很简单,你可以通过迭代算法完成吗?
2. 题解
中序遍历:左中右
2.1. 递归实现
1 | # Definition for a binary tree node. |
或者
1 | # Definition for a binary tree node. |
1 | /** |
2.2. 迭代实现
可以借助栈来完成1
1 | # Definition for a binary tree node. |
1 | /** |
参考资料
1. https://leetcode.cn/problems/binary-tree-inorder-traversal/solutions/412886/er-cha-shu-de-zhong-xu-bian-li-by-leetcode-solutio/ ↩