Very concise JAVA solution


  • 1
    M
        public List<Integer> postorderTraversal(TreeNode root) {
            List<Integer> res = new ArrayList<>();
            Stack<TreeNode> tmp = new Stack<>();
            while(!tmp.empty()||root!=null){
                while(root!=null){
                    res.add(0, root.val);
                    tmp.push(root);
                    root = root.right;
                }
                root = tmp.pop();
                root = root.left;
            }
            return res;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.