Python simple Solution


  • 0
    class Solution(object):
        def reverseBetween(self, head, m, n):
            dummy = ListNode(-1)
            dummy.next = head
            h = dummy
            for i in xrange(m - 1):
                h = h.next
            begin = start = h.next
            pre = None
            for i in xrange(n - m + 1):
                h.next, start.next, start, pre = start, pre, start.next, start
            begin.next = start
            return dummy.next
    

Log in to reply
 

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