Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isBSTPreorder(arr):
- i=0
- N=len(arr)
- 'bound algorithm'
- def create(l,r):
- nonlocal i
- if i==N:return
- if l<=arr[i]<=r:
- t=arr[i]
- i+=1
- create(l,t-1)
- create(t+1,r)
- else:return
- create(float('-inf'),float('inf'))
- return 1 if i==N else 0
- 'coding ninjas'
Advertisement
Add Comment
Please, Sign In to add comment