MCPcopy
hub / github.com/HuberTRoy/leetCode / makeBSTByInorder

Method makeBSTByInorder

Tree/ConvertSortedListToBinarySearchTree.py:128–139  ·  view source on GitHub ↗
(size)

Source from the content-addressed store, hash-verified

126 head = head.next
127
128 def makeBSTByInorder(size):
129 if not size:
130 return
131
132 root = TreeNode(None)
133
134 root.left = makeBSTByInorder(size//2)
135 root.val = self.c_head.val
136 self.c_head = self.c_head.next
137 root.right = makeBSTByInorder(size-size//2-1)
138
139 return root
140
141 return makeBSTByInorder(size)

Callers

nothing calls this directly

Calls 1

TreeNodeClass · 0.85

Tested by

no test coverage detected