---
# System prepended metadata

title: Leetcode 108.

---

# Leetcode 108. Sorted Array To Binary Search Tree

## 題解

```python=
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def sortedArrayToBST(self, nums: List[int]) -> Optional[TreeNode]:
        if len(nums) <= 0:
            return None
        mid = len(nums) // 2
        return TreeNode(
            nums[mid],
            left=self.sortedArrayToBST(nums[:mid]),
            right=self.sortedArrayToBST(nums[mid+1:])
        )
```