function KthNode( proot , k ) {
// write code here
if(!proot || k <1) return -1
let queue = [proot]
let array = [proot]
while(queue.length){
let node = queue.shift()
if(node.left){
queue.push(node.left)
array.push(node.left)
}
if(node.right){
queue.push(node.right)
array.push(node.right)
}
}
array.sort((a,b) => a.val - b.val)
if(k > array.length) return -1
return array[k-1]['val'] || -1
}

京公网安备 11010502036488号