We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9ca58ce commit 81351afCopy full SHA for 81351af
Data-Structure/Tree/Binary Tree/mirrorTree.js
@@ -0,0 +1,35 @@
1
+'use strict';
2
+class Node {
3
+ constructor(data) {
4
+ this.data = data;
5
+ this.leftNode = this.rightNode = null;
6
+ }
7
+}
8
+
9
+function isMirrorTree(root1, root2) {
10
+ if (root1==null && root2==null) return true;
11
+ if ((root1 != null && root2 != null) && (root1.data == root2.data))
12
+ return (isMirrorTree(root1.leftNode, root2.rightNode) && isMirrorTree(root1.rightNode, root2.leftNode))
13
+ return false;
14
15
16
+//level - 1
17
+let tree = new Node(1);
18
19
+// level - 2
20
+tree.leftNode = new Node(2);
21
+tree.rightNode = new Node(2);
22
23
+// level -3
24
+tree.leftNode.leftNode = new Node(3);
25
+tree.leftNode.rightNode = new Node(4);
26
27
+tree.rightNode.leftNode = new Node(4);
28
+tree.rightNode.rightNode = new Node(3);
29
30
+// 1
31
+// / \
32
+// 2 2
33
+// / \ / \
34
+// 3 4 4 3
35
+console.log('Tree is Mirror Tree = ', isMirrorTree(tree, tree));
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments