题目描述
代码如下:
/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public bool isMirror(TreeNode root1,TreeNode root2){
if (root1 == null && root2 == null)
{
return true;
}
else if (root1 == null ^ root2 == null)
{
return false;
}
else if (root1.val != root2.val)
return false;
else
return isMirror(root1.left, root2.right) && isMirror(root1.right, root2.left);
}
public bool IsSymmetric(TreeNode root) {
if (root == null)
return true;
return isMirror(root.left,root.right);
}
}