代码随想录刷题记录-Day14
To Do List
- DAY 13 回顾
- 二叉树的理论知识的理解
- 二叉树的递归遍历三部曲
- DAY 14 总结
DAY 11 回顾
()
二叉树的理论知识的理解
(带补充)
二叉树的递归遍历三部曲(前序、中序、后序)
前序遍历
1 | Difficulty: Easy |
给你二叉树的根节点 root
,返回它节点值的 前序 遍历
Example 1:
1 | Input: root = [1,null,2,3] |
Example 2:
1 | Input: root = [] |
Example 3:
1 | Input: root = [1] |
Constraints:
The number of nodes in the tree is in the range
[0, 100]
.-100 <= Node.val <= 100
Translated by zh-CN
树中节点数目在范围 [0, 100] 内
解法:
(JavaScript)
1 | /** |
PS:
后序遍历
1 | Difficulty: Easy |
Given the root
of a binary tree, return the postorder traversal of its nodes’ values.
Example 1:
1 | Input: root = [1,null,2,3] |
Example 2:
1 | Input: root = [] |
Example 3:
1 | Input: root = [1] |
Constraints:
The number of the nodes in the tree is in the range
[0, 100]
.-100 <= Node.val <= 100
Translated by zh-CN
树中节点数目在范围 [0, 100] 内
解法:
(JavaScript)
1 | /** |
PS:
中序遍历
1 | Difficulty: Easy |
Given the root
of a binary tree, return the inorder traversal of its nodes’ values.
Example 1:
1 | Input: root = [1,null,2,3] |
Example 2:
1 | Input: root = [] |
Example 3:
1 | Input: root = [1] |
Constraints:
- The number of the nodes in the tree is in the range
[0, 100]
. -100 <= Node.val <= 100
Translated by zh-CN
树中节点数目在范围 [0, 100] 内解法:
(JavaScript)
1 | /** |