using System;
using System.Collections.Generic;

/*
public class TreeNode
{
	public int val;
	public TreeNode left;
	public TreeNode right;

	public TreeNode (int x)
	{
		val = x;
	}
}
*/

class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param pRoot TreeNode类 
     * @return bool布尔型
     */
    public bool isSymmetrical (TreeNode pRoot) {
        if(pRoot == null) return true;
        return IsSymmetric2(pRoot.left, pRoot.right);
    }
    public bool IsSymmetric2(TreeNode root1, TreeNode root2){
        if(root1 == null && root2 == null) return true;
        if(root1 == null) return false;
        if(root2 == null) return false;

        if(root1.val != root2.val) return false;
        if(!IsSymmetric2(root1.left, root2.right)) return false;
        if(!IsSymmetric2(root1.right, root2.left)) return false;
        return true;
    }
}