题解 | #二叉树的后序遍历#
二叉树的后序遍历
https://www.nowcoder.com/practice/1291064f4d5d4bdeaefbf0dd47d78541
export function postorderTraversal(root: TreeNode): number[] {
// write code here
const res = []
function traversal(root){
if(root){
// push在这里是前序遍历
traversal(root.left);
// push在这里是中序遍历
traversal(root.right)
// push放在这里是后续遍历
res.push(root.val)
}
}
traversal(root)
return res
}
查看3道真题和解析