| 112 | # self.right = None |
| 113 | |
| 114 | class Solution(object): |
| 115 | def sortedListToBST(self, head): |
| 116 | """ |
| 117 | :type head: ListNode |
| 118 | :rtype: TreeNode |
| 119 | """ |
| 120 | size = 0 |
| 121 | |
| 122 | self.c_head = head |
| 123 | |
| 124 | while head: |
| 125 | size += 1 |
| 126 | head = head.next |
| 127 | |
| 128 | def makeBSTByInorder(size): |
| 129 | if not size: |
| 130 | return |
| 131 | |
| 132 | root = TreeNode(None) |
| 133 | |
| 134 | root.left = makeBSTByInorder(size//2) |
| 135 | root.val = self.c_head.val |
| 136 | self.c_head = self.c_head.next |
| 137 | root.right = makeBSTByInorder(size-size//2-1) |
| 138 | |
| 139 | return root |
| 140 | |
| 141 | return makeBSTByInorder(size) |
nothing calls this directly
no outgoing calls
no test coverage detected