Skip to content

Commit 807c83b

Browse files
authored
Create 114-flatten-binary-tree-to-linked-list.js
1 parent f858c17 commit 807c83b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -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 {void} Do not return anything, modify root in-place instead.
11+
*/
12+
13+
const flatten = function(root) {
14+
let prev = null
15+
function op(root) {
16+
if (root == null) return;
17+
op(root.right);
18+
op(root.left);
19+
root.right = prev;
20+
root.left = null;
21+
prev = root;
22+
}
23+
op(root)
24+
};
25+
26+

0 commit comments

Comments
 (0)