标签:
Binary Tree Postorder Traversal
问题:
Given a binary tree, return the postorder traversal of its nodes‘ values.
思路:
栈方法
我的代码:
public class Solution { public List<Integer> postorderTraversal(TreeNode root) { List<Integer> rst = new ArrayList<Integer>(); if(root == null) return rst; Stack<TreeNode> stack = new Stack<TreeNode>(); stack.push(root); while(!stack.isEmpty()) { TreeNode node = stack.pop(); rst.add(0,node.val); if(node.left != null) stack.push(node.left); if(node.right != null) stack.push(node.right); } return rst; } }
学习之处:
Binary Tree Postorder Traversal
标签:
原文地址:http://www.cnblogs.com/sunshisonghit/p/4345358.html