https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/



Runtime: 379 ms, faster than 72.77% of Python3 online submissions for Convert Sorted List to Binary Search Tree.

Memory Usage: 20.4 MB, less than 32.16% of Python3 online submissions for Convert Sorted List to Binary Search Tree.



```python
class Solution:
    def sortedListToBST(self, head: Optional[ListNode]) -> Optional[TreeNode]:
        #09:14
        rawList = []
        
        node = head
        while node:
            rawList.append(node.val)
            node = node.next
        
        def sorted_list_to_bst(nums):
            if len(nums) == 0:
                return None
            middle_index = len(nums) // 2
            node = TreeNode(val=nums[middle_index])
            node.left = sorted_list_to_bst(nums[0:middle_index])
            node.right = sorted_list_to_bst(nums[middle_index+1:])
            return node
        
        return sorted_list_to_bst(rawList)
        #09:19
```
