forked from partho-maple/coding-interview-gym
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Same_BSTs.py
33 lines (24 loc) · 805 Bytes
/
Same_BSTs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def sameBsts(arrayOne, arrayTwo):
if len(arrayOne) != len(arrayTwo):
return False
if len(arrayOne) == 0 and len(arrayTwo) == 0:
return True
if arrayOne[0] != arrayTwo[0]:
return False
leftOne = getSmaller(arrayOne)
leftTwo = getSmaller(arrayTwo)
rightOne = getBiggerOrEqual(arrayOne)
rightTwo = getBiggerOrEqual(arrayTwo)
return sameBsts(leftOne, leftTwo) and sameBsts(rightOne, rightTwo)
def getSmaller(array):
smaller = []
for i in range(1, len(array)):
if array[i] < array[0]:
smaller.append(array[i])
return smaller
def getBiggerOrEqual(array):
biggerOrEqual = []
for i in range(1, len(array)):
if array[i] >= array[0]:
biggerOrEqual.append(array[i])
return biggerOrEqual