Skip to content

Commit 746d341

Browse files
authored
Create 951-flip-equivalent-binary-trees.js
1 parent 8cb71af commit 746d341

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

951-flip-equivalent-binary-trees.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* function TreeNode(val) {
4+
* this.val = val;
5+
* this.left = this.right = null;
6+
* }
7+
*/
8+
/**
9+
* @param {TreeNode} root1
10+
* @param {TreeNode} root2
11+
* @return {boolean}
12+
*/
13+
const flipEquiv = function(root1, root2) {
14+
if(root1 == null || root2 == null) return root1 === root2
15+
return root1.val === root2.val &&
16+
(
17+
(flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) ||
18+
(flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left))
19+
)
20+
};

0 commit comments

Comments
 (0)