classSolution {BOOLJudge (vector<int>& A,intLeftintRight ) { if(Left>=right)return true; intI=right;//the right of the array at this time is the root while(i>left&&a[i-1]>a[right])-I.;//Find left dial hand tree, I-1 is Zogen for(intj=i-1; j>=left;--j)if(A[j]>a[right])//if the number in the left dial hand tree has a large root number, it is not a binary search return false; for(intj=i;j<right;j++)if(A[j]<a[right])//find the right number of trees, the numbers on the right must be greater than the root . return false; returnJudge (A, left, I-1) && (judge (A, I, right-1));//if Zoki, begin to judge whether Saozi right subtree conforms to binary search tree, from I to right-1 is right subtree, right-1 is right sub -tree root} Public: BOOLVerifysquenceofbst (vector<int>a) {if(!a.size ())return false; returnJudge (A,0, A.size ()-1); }};
New Ket See if the array is not the sequential traversal sequence of the binary search tree