Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add solutions to lc problem: No.0951 #3667

Merged
merged 1 commit into from
Oct 25, 2024
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
feat: add solutions to lc problem: No.0951
  • Loading branch information
rain84 committed Oct 24, 2024
commit b62864980dfeca910b2555f5b89b21e1740941b7
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