New Ket See if the array is not the sequential traversal sequence of the binary search tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.