码迷,mamicode.com
首页 > 其他好文 > 详细

145. Binary Tree Postorder Traversal

时间:2017-10-17 10:03:34      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:pos   logs   tac   null   csharp   public   treenode   res   lis   

class Solution {
    public List<Integer> postorderTraversal(TreeNode root) {
        Stack<TreeNode> stack=new Stack<TreeNode>();
        List<Integer> res=new ArrayList<Integer>();
        while(root!=null||!stack.isEmpty())
        {
            while(root!=null)
            {
                res.add(0, root.val);
                stack.push(root);
                root=root.right;
            }
            root=stack.pop().left;
        }
        return res;
    }
}

  

145. Binary Tree Postorder Traversal

标签:pos   logs   tac   null   csharp   public   treenode   res   lis   

原文地址:http://www.cnblogs.com/asuran/p/7679747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!