Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions solution/0900-0999/0951.Flip Equivalent Binary Trees/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,34 @@ func flipEquiv(root1 *TreeNode, root2 *TreeNode) bool {
}
```

#### TypeScript

```ts
function flipEquiv(root1: TreeNode | null, root2: TreeNode | null): boolean {
if (root1 === root2) return true;
if (!root1 || !root2 || root1?.val !== root2?.val) return false;

const { left: l1, right: r1 } = root1!;
const { left: l2, right: r2 } = root2!;

return (flipEquiv(l1, l2) && flipEquiv(r1, r2)) || (flipEquiv(l1, r2) && flipEquiv(r1, l2));
}
```

#### JavaScript

```js
function flipEquiv(root1, root2) {
if (root1 === root2) return true;
if (!root1 || !root2 || root1?.val !== root2?.val) return false;

const { left: l1, right: r1 } = root1;
const { left: l2, right: r2 } = root2;

return (flipEquiv(l1, l2) && flipEquiv(r1, r2)) || (flipEquiv(l1, r2) && flipEquiv(r1, l2));
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
28 changes: 28 additions & 0 deletions solution/0900-0999/0951.Flip Equivalent Binary Trees/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,34 @@ func flipEquiv(root1 *TreeNode, root2 *TreeNode) bool {
}
```

#### TypeScript

```ts
function flipEquiv(root1: TreeNode | null, root2: TreeNode | null): boolean {
if (root1 === root2) return true;
if (!root1 || !root2 || root1?.val !== root2?.val) return false;

const { left: l1, right: r1 } = root1!;
const { left: l2, right: r2 } = root2!;

return (flipEquiv(l1, l2) && flipEquiv(r1, r2)) || (flipEquiv(l1, r2) && flipEquiv(r1, l2));
}
```

#### JavaScript

```js
function flipEquiv(root1, root2) {
if (root1 === root2) return true;
if (!root1 || !root2 || root1?.val !== root2?.val) return false;

const { left: l1, right: r1 } = root1;
const { left: l2, right: r2 } = root2;

return (flipEquiv(l1, l2) && flipEquiv(r1, r2)) || (flipEquiv(l1, r2) && flipEquiv(r1, l2));
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function flipEquiv(root1, root2) {
if (root1 === root2) return true;
if (!root1 || !root2 || root1?.val !== root2?.val) return false;

const { left: l1, right: r1 } = root1;
const { left: l2, right: r2 } = root2;

return (flipEquiv(l1, l2) && flipEquiv(r1, r2)) || (flipEquiv(l1, r2) && flipEquiv(r1, l2));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function flipEquiv(root1: TreeNode | null, root2: TreeNode | null): boolean {
if (root1 === root2) return true;
if (!root1 || !root2 || root1?.val !== root2?.val) return false;

const { left: l1, right: r1 } = root1!;
const { left: l2, right: r2 } = root2!;

return (flipEquiv(l1, l2) && flipEquiv(r1, r2)) || (flipEquiv(l1, r2) && flipEquiv(r1, l2));
}
Loading