using System.Collections.Generic;
public TreeNode(int x) { this.val = x; this.left = this.right = null; }
private static bool isMirrorTree(TreeNode A, TreeNode B)
if(A == null && B == null){
if(A == null || B == null){
return Program.isMirrorTree(A.left, B.right) && Program.isMirrorTree(A.right, B.left);
public static int isSymmetricTree(TreeNode A){
bool isMirrorTree = Program.isMirrorTree(A.left, A.right);
if(isMirrorTree) { return 1; }else return 0;
public static void Main()
TreeNode A = new TreeNode(1);
A.left = new TreeNode(2);
A.right = new TreeNode(2);
A.left.left = new TreeNode(3);
A.left.right = new TreeNode(4);
A.right.left = new TreeNode(3);
A.right.right = new TreeNode(4);
int _isIdentical = Program.isSymmetricTree(A);
Console.WriteLine("Is Binary Tree Identical: " + _isIdentical);