# 109. Convert Sorted List to Binary Search Tree

**<font color=orange>难度: Medium</font>**

## 刷题内容

> 原题连接

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

> 内容描述

```
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

Example:

Given the sorted linked list: [-10,-3,0,5,9],

One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:

      0
     / \
   -3   9
   /   /
 -10  5
```

## 解题方案

> 思路 1
******- 时间复杂度: O(N)******- 空间复杂度: O(N)******

跟第 108 题一样

```python
class Solution(object):
    def sortedListToBST(self, head):
        """
        :type head: ListNode
        :rtype: TreeNode
        """
        def sortedArrayToBST(nums):
            if not nums:
                return None
            if nums:
                mid = len(nums) / 2
                root = TreeNode(nums[mid])
                root.left = sortedArrayToBST(nums[:mid])
                root.right = sortedArrayToBST(nums[mid+1:])
                return root
        if not head:
            return None
        else:
            lst = []
            while head:
                lst.append(head.val)
                head = head.next
            return sortedArrayToBST(lst)
```
