###109. Convert Sorted List to Binary Search Tree



题目:
<https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/>


难度:

Medium

思路：

跟解array to binary search tree一样，递归，找到list中间点，把它变成root，左边为左树，右边为右子树

值得注意的是需要找到的是list中间的前一个，所以用一个dummy node，然后反复使用linked list找中点的代码

```
class Solution(object):
    def sortedListToBST(self, head):
        """
        :type head: ListNode
        :rtype: TreeNode
        """

        if head == None:
        	return None
        elif head.next == None:
        	return TreeNode(head.val)
        else:
        	dummy = ListNode(-1)
        	dummy.next = head
        	slow, fast = dummy, dummy
        	while fast.next and fast.next.next:
        		slow = slow.next
        		fast = fast.next.next

        	# print slow.val
        	mid = slow.next
        	slow.next = None

        	root = TreeNode(mid.val)
        	root.left = self.sortedListToBST(head)
        	root.right = self.sortedListToBST(mid.next)
        return root
```
