/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
Stack<TreeNode> stack1 = new Stack<TreeNode>();
Stack<Integer> stack2 = new Stack<Integer>();
stack1.push(root);
while(!stack1.isEmpty()){
TreeNode temp = stack1.pop();
if( temp != null){
stack2.push(temp.val);
stack1.push(temp.left);
stack1.push(temp.right);
}
}
List<Integer> results = new ArrayList<Integer>();
while(!stack2.isEmpty()){
results.add(stack2.pop());
}
return results;
}
}
08-04
104
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交