-
Notifications
You must be signed in to change notification settings - Fork 41
/
solution.ts
19 lines (18 loc) · 761 Bytes
/
solution.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class TreeNode {
val: number
left: TreeNode | null
right: TreeNode | null
constructor (val?: number, left?: TreeNode | null, right?: TreeNode | null) {
this.val = (val === undefined ? 0 : val);
this.left = (left === undefined ? null : left);
this.right = (right === undefined ? null : right);
}
}
function flipEquiv (root1: TreeNode | null, root2: TreeNode | null): boolean {
if (root1 !== null && root2 !== null) {
return root1.val === root2.val && ((flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) || (flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left)));
} else if (root1 === null && root2 === null) {
return true;
}
return false;
}