Title description
Operate the given binary tree and transform it into a mirror image of the source binary tree.
The idea is very simple, just recursively traverse the tree, and then swap the left and right subtrees of each node.
import java.util.*;
public class Solution {
public TreeNode Mirror(TreeNode pRoot) {
// write code here
if (pRoot != null) {
TreeNode tmp = pRoot.left;
pRoot.left = pRoot.right;
pRoot.right = tmp;
Mirror(pRoot.left);
Mirror(pRoot.right);
}
return pRoot;
}
}