/**
 * Problem: 226. Invert Binary Tree
 *
 * Idea:
 *
 * Solutions:
 *  invertTree: using invertTreeNode method, recursive calls, do the inversion until no
 * children exists.
 *
 */

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
public class InvertBinaryTree {
    public TreeNode invertTreeNode(TreeNode node) {
        if (node.left != null) {
            invertTreeNode(node.left);
        }

        if (node.right != null) {
            invertTreeNode(node.right);
        }

        TreeNode temp = node.left;
        node.left = node.right;
        node.right = temp;
        return node;
    }

    public TreeNode invertTree(TreeNode root) {
        if (root != null) {
            invertTreeNode(root);
        }
        return root;
    }
/*
    public static void main(String[] args) {
        InvertBinaryTree ibt = new InvertBinaryTree();
        TreeNode tree = new TreeNode(4);
        tree.left = new TreeNode(2);
        tree.left.left = new TreeNode(1);
        tree.left.right = new TreeNode(3);
        tree.right = new TreeNode(7);
        tree.right.left = new TreeNode(6);
        tree.right.right = new TreeNode(9);
        System.out.println(ibt.invertTree(tree));
    }*/
}

@@ -120,14 +120,10 @@
 sive
- calls
+ly
 , do
@@ -166,16 +166,70 @@
 exists.%0A
+ *  invertTreeCombined: simplified invertTree method.%0A
  *%0A */%0A%0A
@@ -923,16 +923,331 @@
 t;%0A    %7D
+%0A%0A    public TreeNode invertTreeCombined(TreeNode root) %7B%0A        if (root == null) %7B%0A            return root;%0A        %7D%0A%0A        TreeNode left = invertTreeCombined(root.left);%0A        TreeNode right = invertTreeCombined(root.right);%0A        root.left = right;%0A        root.right = left;%0A%0A        return root;%0A    %7D
 %0A/*%0A    

Add new simplified solution