题解 | #二叉搜索树的后序遍历序列#
二叉搜索树的后序遍历序列
https://www.nowcoder.com/practice/a861533d45854474ac791d90e447bafd
function check(sequence,l,r){ if(l>=r) return true let root = sequence[r] let j = r-1 while(j>=0&&sequence[j]>root) j-- for(let i=l;i<=j;i++){ if(sequence[i]>root) return false } return check(sequence,l,j)&&check(sequence,j+1,r-1) } function VerifySquenceOfBST(sequence) { let r = sequence.length if(r===0) return false return check(sequence,0,r-1) } module.exports = { VerifySquenceOfBST : VerifySquenceOfBST };