题目描述:
给你一个二叉树的根节点 root , 检查它是否轴对称。
示例 1:
输入:root = [1,2,2,3,4,4,3]
输出:true
示例 2:
输入:root = [1,2,2,null,3,null,3]
输出:false
var isSymmetric = function (root) {
function isSame(left, right) {
if (left == null && right != null || left != null && right == null) {
return false
}
if (left === null && right === null) {
return true
}
if (left.val != right.val) {
return false
}
return isSame(left.left, right.right) && isSame(left.right, right.left)
}
if (root === null) {
return true
} else {
return isSame(root.left, root.right)
}
};