2
def __init__(self, start, end, val):9
def insertable(self, node):10
if node.end <= node.start:12
if node.end <= self.start:16
return self.left.insertable(node)17
elif node.start >= self.end:21
return self.right.insertable(node)24
leftS = min(self.start, node.start)25
leftE = max(self.start, node.start)26
rightS = min(self.end, node.end)27
rightE = max(self.end, node.end)28
if not self.left and not self.right:31
return self.right.insertable(Node(rightS, rightE, 1))33
return self.left.insertable(Node(leftS, leftE, 1))35
resL = self.left.insertable(Node(leftS, leftE, 1))36
resR = self.right.insertable(Node(rightS, rightE, 1))43
def insert(self, node):44
if node.end <= node.start:47
if node.end <= self.start:51
self.left.insert(node)52
elif node.start >= self.end:56
self.right.insert(node)58
leftS = min(self.start, node.start)59
leftE = max(self.start, node.start)60
rightS = min(self.end, node.end)61
rightE = max(self.end, node.end)63
self.start, self.end = leftE, rightS64
if not self.left and not self.right:65
self.left = Node(leftS, leftE, 1) if leftS < leftE else None66
self.right = Node(rightS, rightE, 1) if rightS < rightE else None68
self.left = Node(leftS, leftE, 1) if leftS < leftE else None69
self.right.insert(Node(rightS, rightE, 1))71
self.right = Node(rightS, rightE, 1) if rightS < rightE else None72
self.left.insert(Node(leftS, leftE, 1))74
self.left.insert(Node(leftS, leftE, 1))75
self.right.insert(Node(rightS, rightE, 1))84
def book(self, start: int, end: int) -> bool:86
self.root = Node(start, end, 1)89
newNode = Node(start, end, 1)90
if self.root.insertable(newNode):91
self.root.insert(newNode)