| 51 | # self.right = None |
| 52 | |
| 53 | class Solution(object): |
| 54 | def sortedArrayToBST(self, nums): |
| 55 | """ |
| 56 | :type nums: List[int] |
| 57 | :rtype: TreeNode |
| 58 | """ |
| 59 | if not nums: |
| 60 | return None |
| 61 | |
| 62 | def makeBinarySearchTree(nums): |
| 63 | mid = len(nums) // 2 |
| 64 | |
| 65 | root = TreeNode(nums[mid]) |
| 66 | left = nums[:mid] |
| 67 | right = nums[mid+1:] |
| 68 | |
| 69 | if left: |
| 70 | root.left = makeBinarySearchTree(left) |
| 71 | if right: |
| 72 | root.right = makeBinarySearchTree(right) |
| 73 | |
| 74 | return root |
| 75 | |
| 76 | root = makeBinarySearchTree(nums) |
| 77 | return root |
| 78 |
nothing calls this directly
no outgoing calls
no test coverage detected