Invert a binary tree

public static TreeNode invertBinaryTree(TreeNode root) {
if (root == null) {
return null;
}
TreeNode leftSubTree = invertBinaryTree(root.right);
TreeNode rightSubTree = invertBinaryTree(root.left);
root.left = leftSubTree;
root.right = rightSubTree;
return root;
}

Leave a Reply

Your email address will not be published. Required fields are marked *