@@ -0,0 +1,2682 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0Aimport java.util.Stack;%0A%0A/**%0A * https://leetcode.com/problems/binary-tree-postorder-traversal/%0A */%0Apublic class Problem145 %7B%0A    public static class TreeNode %7B%0A        int val;%0A        TreeNode left;%0A        TreeNode right;%0A%0A        TreeNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public List%3CInteger%3E postorderTraversal(TreeNode root) %7B%0A        List%3CInteger%3E result = new ArrayList%3C%3E();%0A        Set%3CTreeNode%3E set = new HashSet%3C%3E();%0A        Stack%3CTreeNode%3E stack = new Stack%3C%3E();%0A        stack.add(root);%0A        boolean right = false;%0A        while (!stack.isEmpty()) %7B%0A            TreeNode node = stack.pop();%0A            while (node.left == null) %7B%0A                TreeNode n = node.left;%0A                stack.add(n);%0A            %7D%0A            %0A            System.out.println(%22popping: %22 + node.val);%0A            while ((node.left == null %7C%7C set.contains(node.left))%0A                && (node.right == null %7C%7C set.contains(node.right))) %7B%0A                System.out.println(node.val);%0A                result.add(node.val);%0A                set.add(node);%0A            %7D%0A            if (node.left != null) %7B%0A                System.out.println(%22adding: %22 + node.left.val);%0A                stack.add(node.left);%0A                right = false;%0A            %7D else %7B%0A                right = true;%0A                if (right) %7B%0A                    if (node.right != null) %7B%0A                        System.out.println(%22adding: %22 + node.right.val);%0A                        stack.add(node.right);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A        return result;%0A    %7D%0A%0A    private List%3CInteger%3E recursivePostOrderTraversal(TreeNode root) %7B%0A        List%3CInteger%3E result = new ArrayList%3C%3E();%0A        recursivePostOrderTraversal(root, result);%0A        return result;%0A    %7D%0A%0A    private void recursivePostOrderTraversal(TreeNode root, List%3CInteger%3E result) %7B%0A        if (root == null) %7B%0A            return;%0A        %7D%0A        recursivePostOrderTraversal(root.left, result);%0A        recursivePostOrderTraversal(root.right, result);%0A        result.add(root.val);%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        TreeNode root = new TreeNode(1);%0A        root.left = new TreeNode(2);%0A        root.right = new TreeNode(3);%0A        root.left.left = new TreeNode(4);%0A        root.left.right = new TreeNode(5);%0A        root.left.right.right = new TreeNode(6);%0A%0A        Problem145 prob = new Problem145();%0A//        System.out.println(prob.recursivePostOrderTraversal(root));%0A        System.out.println(prob.postorderTraversal(root));%0A    %7D%0A%7D%0A

Create a skeleton for problem 145