/*
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution { // 递归调用
    boolean isSymmetrical(TreeNode pRoot) {
        if (pRoot == null) {
            return true;
        }
        TreeNode left = pRoot.left;
        TreeNode right = pRoot.right;
        return doSymmetrical(left, right);
    }
    
    private boolean doSymmetrical(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        else if (left != null && right != null) {
            boolean tmp = left.val == right.val;
            return tmp && doSymmetrical(left.left, right.right) && doSymmetrical(left.right, right.left);
        } else {
            return false;
        }
    }
}