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

```c++
class Solution {
public:

}

TreeNode* build(ListNode* start, ListNode* end) {
if(start == end) {
return NULL;
}

ListNode* fast = start;
ListNode* slow = start;

while(fast != end && fast->next != end) {
slow = slow->next;
fast = fast->next->next;
}

TreeNode* node = new TreeNode(slow->val);
node->left = build(start, slow);
node->right = build(slow->next, end);

return node;
}
};
```

# Convert Sorted Array to Binary Search Tree

> Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

```c++
class Solution {
public:
TreeNode *sortedArrayToBST(vector &num) {
return build(num, 0, num.size());
}

TreeNode* build(vector& num, int start, int end) {
if(start >= end) {
return NULL;
}

int mid = start + (end - start) / 2;

TreeNode* node = new TreeNode(num[mid]);
node->left = build(num, start, mid);
node->right = build(num, mid + 1, end);

return node;
}
};
```