# C#LeetCode刷题之#101-对称二叉树（Symmetric Tree）

1
/   \
2     2
/ \    / \

3  4 4  3

1
/   \
2     2
\     \
3    3

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

For example, this binary tree [1,2,2,3,4,4,3] is symmetric:

1
/   \
2     2
/ \    / \

3  4 4  3

But the following [1,2,2,null,3,null,3] is not:

1
/   \
2     2
\     \
3    3

Note:Bonus points if you could solve it both recursively and iteratively.

```public class Program {

public static void Main(string[] args) {
var root = new TreeNode(1) {
left = new TreeNode(2),
right = new TreeNode(2)
};

var res = IsSymmetric(root);
Console.WriteLine(res);

}

public static bool IsSymmetric(TreeNode root) {
return Symmetric(root, root);
}

public static bool Symmetric(TreeNode node1, TreeNode node2) {
//都为空时，递归终止，为镜像二叉树
if(node1 == null && node2 == null) return true;
//有一个为空时，递归终止，不是镜像二叉树
if(node1 == null || node2 == null) return false;
//递归判定
return node1.val == node2.val &&
Symmetric(node1.left, node2.right) &&
Symmetric(node1.right, node2.left);
}

public class TreeNode {
public int val;
public TreeNode left;
public TreeNode right;
public TreeNode(int x) { val = x; }
}

}```

`True`

(2)