Skip to content

Commit f869b7c

Browse files
authored
Update 156-binary-tree-upside-down.js
1 parent 18b0779 commit f869b7c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

156-binary-tree-upside-down.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ const upsideDownBinaryTree = function(root) {
2424
}
2525
return prev
2626
}
27+
28+
// another
29+
30+
const upsideDownBinaryTree = function(root) {
31+
if (root == null || root.left == null) {
32+
return root
33+
}
34+
const newRoot = upsideDownBinaryTree(root.left)
35+
root.left.left = root.right
36+
root.left.right = root
37+
root.left = null
38+
root.right = null
39+
return newRoot
40+
}

0 commit comments

Comments
 (0)