二叉搜索树的后序遍历

class Solution():
    def ifBSTpost(self,A):
        if A == []:
            return True
        root = A[-1]
        left = []
        right =[]
        for i in A[:-1]:
            if i > root:
                break
            left.append(i)

        indexright = len(left)

        for i in range(indexright,len(A)-2):
            if A[i] < root:
                return False
            right.append(A[i])

        self.ifBSTpost(left)
        self.ifBSTpost(right)

        return True





#test
s = Solution()

print(s.ifBSTpost([6,5,4]))

你可能感兴趣的:(二叉搜索树的后序遍历)