My Python Solution

  • 0
    class Solution(object):
        def sortedListToBST(self, head):
            if not head:
            if not
                return TreeNode(head.val)
            fast = head
            slow = None
            while fast and
                fast =
                slow = head if slow is None else
            node = TreeNode(
            tmp =
   = None
            node.left = self.sortedListToBST(head)
            node.right = self.sortedListToBST(tmp)
            return node

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.