contains category wise problems(data structures, competitive) of popular platforms.
View the Project on GitHub mayankdutta/category-wise-problems
Tags: tree dfs
Convert binary tree to mirror tree
/*************************************************************
Following is the Binary Tree node structure:
class BinaryTreeNode
{
int data;
BinaryTreeNode left;
BinaryTreeNode right;
BinaryTreeNode(int data) {
this.data = data;
this.left = null;
this.right = null;
}
}
*************************************************************/
public class Solution {
public static BinaryTreeNode fun(BinaryTreeNode node) {
if (node == null) {
return node;
}
node.left = fun(node.left);
node.right = fun(node.right);
BinaryTreeNode temp = node.right;
node.right = node.left;
node.left = temp;
return node;
}
public static void mirrorTree(BinaryTreeNode node) {
node = fun(node);
}
}