import java.util.*;

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

public class Solution {

    boolean flg = true;
    /**
     * 
     * @param root TreeNode类 
     * @return bool布尔型
     */
    public boolean isSymmetric (TreeNode root) {

        if (root == null) {
            return true;
        }

        treeDeep(root.left, root.right);
        return flg;
    }

    public void treeDeep (TreeNode left, TreeNode right) {

        if (left == null && right == null) {
            return;
        }

        if (left == null && right != null) {
            flg = false;
            return;
        }

        if (left != null && right == null) {
            flg = false;
            return;
        }

        if (left.val != right.val) {
            flg = false;
            return;
        }

        treeDeep(left.left, right.right);
        treeDeep(left.right, right.left);
    }
}