class Solution:
    def reverseBetween(self, head, m, n):
        """
        :type head: ListNode
        :type m: int
        :type n: int
        :rtype: ListNode
        """
        res,res1=[],[]
        while head:
            res.append(head)
            head=head.next
        temp=res[m-1:n]
        temp.reverse()
        res1=res[:m-1]+temp+res[n:]
        ans=pre=ListNode(-1)
        for i in range(len(res1)):
            pre.next=res1[i]
            pre=pre.next
        pre.next=None
        return ans.next