Given a binary tree, return the postorder traversal of its nodes’ values.
1 | For example : |
题意:
二叉树的后续遍历。
思路:
方法一:
递归实现。
1 | class Solution |
方法二:
非递归实现,后续遍历非递归实现的一个难点,就是要有一个临时节点指针来记录右子树节点是否是被访问过的,如果右子树为空,或者被访问过,则当前节点可以进去结果集。
1 | class Solution |
Given a binary tree, return the postorder traversal of its nodes’ values.
1 | For example : |
二叉树的后续遍历。
递归实现。
1 | class Solution |
非递归实现,后续遍历非递归实现的一个难点,就是要有一个临时节点指针来记录右子树节点是否是被访问过的,如果右子树为空,或者被访问过,则当前节点可以进去结果集。
1 | class Solution |