File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for a binary tree node.
3
+ * function TreeNode(val, left, right) {
4
+ * this.val = (val===undefined ? 0 : val)
5
+ * this.left = (left===undefined ? null : left)
6
+ * this.right = (right===undefined ? null : right)
7
+ * }
8
+ */
9
+ /**
10
+ * @param {TreeNode } root
11
+ * @param {number } from
12
+ * @param {number } to
13
+ * @return {TreeNode }
14
+ */
15
+ const correctBinaryTree = ( root , seen = new Set ( ) , found = false ) => {
16
+ const go = ( root ) => {
17
+ seen . add ( root )
18
+ if ( root . right && seen . has ( root . right ) ) {
19
+ found = true
20
+ return null
21
+ }
22
+ if ( ! found && root . right ) root . right = go ( root . right )
23
+ if ( ! found && root . left ) root . left = go ( root . left )
24
+ return root
25
+ }
26
+ return go ( root )
27
+ }
28
+
29
+ // another
30
+
1
31
/**
2
32
* Definition for a binary tree node.
3
33
* function TreeNode(val, left, right) {
You can’t perform that action at this time.
0 commit comments