Accepted Python solution. In place and in one-pass.

  • 0

    Below is my solution. Any comments?

    class Solution:
        # @param head, a ListNode
        # @param m, an integer
        # @param n, an integer
        # @return a ListNode
        def reverseBetween(self, head, m, n):
            if == None:
                return head
            dummyhead = ListNode(0)
   = head
            prev = dummyhead
            for i in range(m-1):
                prev =
            one =
            two =
            first =
            for i in range(0, n-m):
                rest =
       = two
       = one
       = rest
                one = two
                two = rest

Log in to reply

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