## 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.

### Analysis:

The easier way to solve this problem is use the idea as the previous one.
Here present another way of thinking.
In the previous array to BST, we construct the BST in a top-down way. For the list data structure, to get the mid point every time is a waster of time. So construct the BST in a bottom-up way. However, the length of the list must be computed.

Recursively
1. construct the left tree
2. construct the root node, list pointer +1.
3. construct the right node

Note that in Python, the function argument is more like a "pass by value" way if the argument is immutable, to use the C++ like "pass by reference", the argument should be a mutable type, here in the code, a list of "ListNode" is used.

### Code(C++):

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
/**
* Definition for binary tree
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:

TreeNode *l2bst(ListNode* &head,int st, int ed){
if (st>ed) {return NULL;}
parent->left  = lefttree;
parent->right  = righttree;
return parent;
}

// Start typing your C/C++ solution below
// DO NOT write int main() function
int len = 0;
while (h){
len = len+1;
h = h->next;
}
return root;

}
};


### Code(Python):

# Definition for a  binary tree node
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
#
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
# @param head, a list node
# @return a tree node
if st > ed or head[0] == None:
return None
mid = st + (ed - st)/2
left = self.bst(head, st, mid - 1)
right = self.bst(head, mid + 1, ed)
root.left = left
root.right = right
return root

return None
n = 0
while tmp != None:
n += 1
tmp = tmp.next