var verifyPostorder = function(postorder) {
if(postorder.length<=1){
return true;
}
var rootVal = postorder[postorder.length-1];
var left = [];
var right = [];
let i=0;
while(postorder[i]<rootVal){//[0,i)
left.push(postorder[i])
i++;
}
while(postorder[i]!==rootVal){
if(postorder[i]<rootVal){
return false;
}
right.push(postorder[i]);
i++;
}
return verifyPostorder(left)&&verifyPostorder(right)
};
二叉搜索树的后序遍历序列
最新推荐文章于 2024-11-04 16:38:59 发布