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 8dc01dc commit 18b0779Copy full SHA for 18b0779
156-binary-tree-upside-down.js
@@ -0,0 +1,26 @@
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} root
10
+ * @return {TreeNode}
11
12
+const upsideDownBinaryTree = function(root) {
13
+ let curr = root
14
+ let next = null
15
+ let temp = null
16
+ let prev = null
17
+ while (curr !== null) {
18
+ next = curr.left
19
+ curr.left = temp
20
+ temp = curr.right
21
+ curr.right = prev
22
+ prev = curr
23
+ curr = next
24
+ }
25
+ return prev
26
+}
0 commit comments