Title Description
Enter an integer array, the array is not the result of the determination after traversing a binary search tree. If the output Yes, otherwise the output No. Suppose the input array of any two numbers are different from each other.
This question is particularly silly place:
Return false empty when the input sequence, but to be recursive procedure returns true null
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def VerifySquenceOfBST(self, sequence): 4 # write code here 5 if sequence==[]: 6 return False 7 rootNum=sequence[-1] 8 del sequence[-1] 9 index=None 10 for i in range(len(sequence)): 11 if index == None and sequence[i]>rootNum: 12 index = i 13 if index !=None and sequence[i]< rootNum: 14 return False 15 if sequence[:index]==[]: 16 left = True 17 else: 18 left = self.VerifySquenceOfBST(sequence[:index]) 19 if sequence[index:]==[]: 20 right = True 21 else: 22 right = self.VerifySquenceOfBST(sequence[index:]) 23 return left and right
2019-12-12 08:56:33