Follow-up traversal of binary search tree

Source: Internet
Author: User

The title description enters an array of integers to determine if the array is the result of a sequential traversal of a binary search tree. If yes, output yes, otherwise output No. Assume that any two digits of the input array are different.
#-*-Coding:utf-8-*-class Solution:    def verifysquenceofbst (self, Sequence):        # Write code here        if not Sequen CE:            return False        root = sequence[-1]        i = 0        while sequence[i] < root:            i = i+ 1        for J in range (I, Len (Sequence)-1):            if SEQUENCE[J] < root:                return False Left        = sequence[:i] Right        =sequence[i:len (sequence)-1]        leftis = True        rightis =true        If Len (left) > 0:            leftis = self. Verifysquenceofbst (left)        if Len (right) > 0:            rightis = self. Verifysquenceofbst (right)        return Leftis and Rightis

Follow-up traversal of 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.