题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5
JS版本
/* function TreeNode(x) { this.val = x; this.left = null; this.right = null; } */ function inorder(arr, pRootOfTree) { if (pRootOfTree === null) return; inorder(arr, pRootOfTree.left); arr.push(pRootOfTree); inorder(arr, pRootOfTree.right); } function Convert(pRootOfTree) { // write code here let arr = [] inorder(arr, pRootOfTree) for(let i = 0; i< arr.length - 1; ++i) { arr[i].right = arr[i + 1] arr[i + 1].left = arr[i] } return arr[0] } module.exports = { Convert: Convert, };