Skip to content

Latest commit

 

History

History
42 lines (27 loc) · 800 Bytes

0145-binary-tree-postorder-traversal.adoc

File metadata and controls

42 lines (27 loc) · 800 Bytes

145. Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes' values.

Example:

Input: [1,null,2,3]
   1
    \
     2
    /
   3

Output: [3,2,1]

Follow up: Recursive solution is trivial, could you do it iteratively?

解题分析

这个题有些麻烦。

我的解法是使用 StackSet(保存处理过子节点,直接弹出,不再处理)。

还可以使用两个 Stack

甚至一个 Stack

link:{sourcedir}/_0145_BinaryTreePostorderTraversal.java[role=include]

思考题

如何使用一个栈来解决这个问题?