Skip to content

Commit 7b4952d

Browse files
committed
86
1 parent 72d7b75 commit 7b4952d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

Day86/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* // Definition for a Node.
3+
* function Node(val, left, right) {
4+
* this.val = val;
5+
* this.left = left;
6+
* this.right = right;
7+
* };
8+
*/
9+
10+
/**
11+
* @param {Node} root
12+
* @return {Node}
13+
*/
14+
var treeToDoublyList = function (root) {
15+
16+
if (!root) return null;
17+
let head = null;
18+
let prev = null;
19+
20+
function inOrder(node) {
21+
if (!node) return null;
22+
inOrder(node.left);
23+
24+
//do stuff
25+
if (prev == null) {
26+
prev = node
27+
head = node
28+
} else {
29+
node.left = prev;
30+
prev.right = node;
31+
prev = node
32+
}
33+
34+
inOrder(node.right)
35+
}
36+
inOrder(root);
37+
38+
head.left = prev;
39+
prev.right = head;
40+
return head
41+
};

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,6 @@ If you are loving solving problems in leetcode, please contact me to enjoy it to
190190

191191
|Day 84| [1640. Check Array Formation Through Concatenation](https://leetcode.com/problems/check-array-formation-through-concatenation/) | [javascript]()|[:memo:](https://leetcode.com/problems/check-array-formation-through-concatenation/)|Easy|
192192

193-
|Day 85| [1640. Check Array Formation Through Concatenation](https://leetcode.com/problems/palindrome-permutation/) | [javascript]()|[:memo:](https://leetcode.com/problems/palindrome-permutation/)|Easy|
193+
|Day 85| [1640. Check Array Formation Through Concatenation](https://leetcode.com/problems/palindrome-permutation/) | [javascript]()|[:memo:](https://leetcode.com/problems/palindrome-permutation/)|Easy|
194+
195+
|Day 86| [426. Convert Binary Search Tree to Sorted Doubly Linked Lis](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/submissions/) | [javascript]()|[:memo:](https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/submissions/)|Medium|

0 commit comments

Comments
 (0)