图片说明

/*
 * function TreeNode(x) {
 *   this.val = x;
 *   this.left = null;
 *   this.right = null;
 * }
 */

/**
  * 
  * @param root TreeNode类 
  * @return bool布尔型
  */
function isSymmetric( root ) {
    // write code here
    if(!root) return true
    function isSame(left,right){
        if(!left && !right){
            return true
        }
        if(!left || !right){
            return false
        }
        if(left.val !== right.val){
            return false
        }
        return isSame(left.right,right.left) && isSame(left.left,right.right)
    }
    return isSame(root.left,root.right)
}
module.exports = {
    isSymmetric : isSymmetric
};