题解 | #二叉搜索树的第k个节点#
二叉搜索树的第k个节点
https://www.nowcoder.com/practice/57aa0bab91884a10b5136ca2c087f8ff
function KthNode( proot , k ) { if(proot===null) return -1; // write code here let arr = []; function search(root,arr){ if(!root) return; arr.push(root.val); search(root.left,arr); search(root.right,arr); return arr; } arr = search(proot,arr); function comp(a,b){ return a-b; } let newarr = arr.sort(comp); if(k>newarr.length || k===0) return -1; return newarr[k-1]; } module.exports = { KthNode : KthNode };