Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 4x 14x 6x 8x 1x 7x 1x 6x 4x 1x 3x | import type { TreeNode } from './Tree'
export default function isSymmetric<T>(root: TreeNode<T> | null): boolean {
const dfs = (
left: TreeNode<T> | null,
right: TreeNode<T> | null,
): boolean => {
if (left === null && right === null)
return true
if (left === null || right === null)
return false
if (left.val !== right.val)
return false
return dfs(left.left, right.right) && dfs(left.right, right.left)
}
if (root === null)
return true
return dfs(root.left, root.right)
}
|