A Iterative PostOrder Traversal Java Solution
A recursive method is straightforward. Doing it iteratively is a lot of fun. I use postorder traversal to realize a iterative version.\n\n    public class Solut
A recursive method is straightforward. Doing it iteratively is a lot of fun. I use postorder traversal to realize a iterative version.\n\n    public class Solution {\n        public boolean isBalanced(TreeNode root) {\n            if(root==null) return true;\n            Stack<TreeNode> stack = new Stack<TreeNode>();\n            Map<TreeNode, Integer> map = new HashMap<TreeNode, Integer>();\n            stack.push(root);\n            while(!stack.isEmpty()){\n                TreeNode node = stack.pop();\n                if((node.left==null || node.left!=null && map.containsKey(node.left)) &&(node.right==null || node.right!=null && map.containsKey(node.right))){\n                    int left = node.left==null?0:map.get(node.left);\n                    int right = node.right==null?0:map.get(node.right);\n                    if(Math.abs(left-right) > 1) return false;\n                    map.put(node, Math.max(left, right)+1);\n                }else{\n                    if(node.left!=null && !map.containsKey(node.left)){\n                        stack.push(node);\n                        stack.push(node.left);\n                    }else{\n                        stack.push(node);\n                        stack.push(node.right);\n                    }\n                }\n            }\n            return true;\n        }\n    }
['Iterator', 'Java']