python solution using fast, slow pointers

  • 0
        def sortedListToBST(self, head):
            if head is None:
                return None
            s, f, t = head, head, None
            while f and
                t = s
                s =
                f =
            if t:
       = None
                head = None
            tree = TreeNode(s.val)
            tree.left = self.sortedListToBST(head)
            tree.right = self.sortedListToBST(
            return tree

Log in to reply

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