@Test public void invertTree() { TreeNode root0 = new TreeNode(0); TreeNode left1 = new TreeNode(1); TreeNode right1 = new TreeNode(2); TreeNode left21 = new TreeNode(21); TreeNode right22 = new TreeNode(22); TreeNode left23 = new TreeNode(23); TreeNode right24 = new TreeNode(24); root0.left = left1; root0.right = right1; left1.left = left21; left1.right = right22; right1.left = left23; right1.right = right24; assertEquals(22, root0.left.right.val); assertEquals(23, InvertBinaryTreeSolution.invertTreeRecursion(root0).left.right.val); }
static TreeNode invertTreeRecursion(TreeNode root) { if (root == null) return null; final TreeNode left = root.left, right = root.right; root.left = invertTreeRecursion(right); root.right = invertTreeRecursion(left); return root; }
InvertBinaryTreeSolution { static TreeNode invertTreeRecursion(TreeNode root) { if (root == null) return null; final TreeNode left = root.left, right = root.right; root.left = invertTreeRecursion(right); root.right = invertTreeRecursion(left); return root; } }
InvertBinaryTreeSolution { static TreeNode invertTreeRecursion(TreeNode root) { if (root == null) return null; final TreeNode left = root.left, right = root.right; root.left = invertTreeRecursion(right); root.right = invertTreeRecursion(left); return root; }  }
InvertBinaryTreeSolution { static TreeNode invertTreeRecursion(TreeNode root) { if (root == null) return null; final TreeNode left = root.left, right = root.right; root.left = invertTreeRecursion(right); root.right = invertTreeRecursion(left); return root; }   }
InvertBinaryTreeSolution { static TreeNode invertTreeRecursion(TreeNode root) { if (root == null) return null; final TreeNode left = root.left, right = root.right; root.left = invertTreeRecursion(right); root.right = invertTreeRecursion(left); return root; }    }