145. Binary Tree Postorder Traversal

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;
    }
}

  

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