例如, (5,3,7,2,4,6,8) 中,按结点数值大小顺序第三小结点的值为4。
function KthNode(pRoot, k)
{
// write code here
if( pRoot == null || k<1 ){
return null;
}
var arr = [];
function sort(root){
if( root == null ){
return null;
}
sort(root.left);
arr.push(root);
sort(root.right);
}
sort(pRoot);
return arr[k-1];
/*
var temp = [];
temp = Arrays.sort(pRoot);
return temp[k-1];
*/
}

京公网安备 11010502036488号