Mirror Tree
Recursive
- http://blog.csdn.net/craiglin1992/article/details/44760121
TreeNode mirror(TreeNode root) { if (root == NULL) return NULL; else { TreeNode newNode = new TreeNode(root.val); newNode->left = mirror(root->right); newNode->right = mirror(root->left); return newNode; } }
Iterative
public boolean isMirrorImage(Node root1, Node root2) {
if (root1 == null && root2 == null) {
return true;
}
if (root1 != null && root2 != null && root1.val == root2.val) {
return isMirrorImage(root1.left, root2.right) && isMirrorImage(root1.right, root2.left);
}
return false;
}