题解 | #二叉搜索树的后序遍历序列#
二叉搜索树的后序遍历序列
https://www.nowcoder.com/practice/a861533d45854474ac791d90e447bafd
function split(list){
//出口
if(list.length == 0){
return true;
}
//浅拷贝
let list_copy1 = [];
let list_copy2 = [];
for(let i=0;i<list.length;i++){
list_copy1.push(list[i]);
list_copy2.push(list[i]);
}
let count = 0;
let root = list[list.length-1];
while(list[count] < list[list.length-1]){
count += 1;
}
for(let i=count;i<list.length-1;i++){
if(list[i] <= root){
return false;
}
}
let left = [];
let right = []
// if()
left = list_copy1.splice(0,count);
if(count < list.length - 1){
right = list_copy2.splice(count,list.length-1);
}
return split(left) && split(right);
}
function VerifySquenceOfBST(sequence)
{
// write code here
if(sequence.length == 0){
return false;
}
return split(sequence);
}
module.exports = {
VerifySquenceOfBST : VerifySquenceOfBST
};
#我的实习求职记录#

