Leetcode: Invert Binary Tree May 4 2015 Invert a binary tree. 12345 4 / \ 2 7 / \ / \1 3 6 9 to 12345 4 / \ 7 2 / \ / \9 6 3 1 The basic idea is to use LinkedHashMap, as it has property - capacity. 1234567891011121314151617181920212223242526272829303132/** * Created by hzhou on 2015/6/13. * Email: i@hzhou.me */public class InvertBinaryTree { public TreeNode invertTree(TreeNode root) { if (root == null) { return null; } Queue<TreeNode> queue = new LinkedList<TreeNode>(); queue.add(root); while (!queue.isEmpty()) { TreeNode node = queue.poll(); TreeNode left = node.left; TreeNode right = node.right; // exchange left with right node.left = right; node.right = left; if (left != null) { queue.add(left); } if (right != null) { queue.add(right); } } return root; }}