Skip to content

Commit 4570f51

Browse files
committed
052
1 parent 2ba1a22 commit 4570f51

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

052.is-bst-array.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
inp1 = [10,15,8,12,94,81,5,2,11]
2+
inp2 = [10,8,5,15,2,12,11,94,81]
3+
4+
def isBsts(arr1,arr2):
5+
if len(arr1) != len(arr2): return False
6+
if len(arr1)==0 and len(arr2)==0: return True
7+
if arr1[0] != arr2[0]: return False
8+
9+
left1 = getSmaller(arr1)
10+
right1 = getGreater(arr1)
11+
left2 = getSmaller(arr2)
12+
right2 = getGreater(arr2)
13+
14+
return isBsts(left1,left2) and isBsts(right1,right2)
15+
16+
17+
def getSmaller(arr):
18+
small = []
19+
for i in range(1,len(arr)):
20+
if arr[i] < arr[0]: small.append(arr[i])
21+
return small
22+
23+
def getGreater(arr):
24+
greater = []
25+
for i in range(1,len(arr)):
26+
if arr[i] > arr[0]: greater.append(arr[i])
27+
return greater
28+
29+
30+
31+
print(isBsts(inp1,inp2))

0 commit comments

Comments
 (0)