题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
http://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5
/* function TreeNode(x) {
this.val = x;
this.left = null;
this.right = null;
} */
function Convert(pRootOfTree)
{
let head = null
let p = null
function traversal(root) {
if(root === null) return
traversal(root.left)
if(root.left === null && head === null) {
head = p = root
} else {
p.right = root
root.left = p
p = root
}
traversal(root.right)
}
traversal(pRootOfTree)
return head
}
module.exports = {
Convert : Convert
};