1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
var isSymmetric = function (root) { if (!root) { return true; }
return isSameNode(root.left, root.right) && isSameNode(root.right, root.left); };
function isSameNode(left, right) { if (!left && !right) { return true; } else if (!left || !right) { return false; } else if (left.val === right.val) { return isSameNode(left.left, right.right) && isSameNode(right.right, left.left); } return false; }
|