标签:
class Solution { public: bool isBST(vector<int> &s,int a,int b) { if(b<a) return false; if(b==a) return true; int root=s[b]; int i,j; for(i=a;i<=b-1;i++) if(s[i]>root)break; bool left=true; if(i>a) left=isBST(s,a,i-1); for(j=i;j<=b-1;j++) if(s[j]<root)return false; bool right=true; if(i<b-1) return isBST(s,i,b-1); return left&&right; } bool VerifySquenceOfBST(vector<int> sequence) { if(sequence.size()<0||sequence.size()==0) return false; if(sequence.size()==1) return true; int len=sequence.size(); return isBST(sequence,0,len-1); } };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5356984.html