Python 3 Solution Single pass


#1
def reverseBetween(self, A, B, C):
    dummy = tail = ListNode(0)
    dummy.next = A
    curr = A
    prev = None
    next_ele = None
    conttill = C-B
    count = 1
    flag = 0
    while curr:
        tail2 = curr
        while curr and conttill>-1 and count==B:
            next_ele = curr.next
            curr.next = prev
            prev = curr
            curr = next_ele
            conttill -= 1
            flag = 1
        if flag == 1:
            tail.next = prev
            tail = tail2
            tail2.next = curr
            flag = 0
        else:
            tail.next = curr
            tail = curr
            curr = curr.next
        count+=1
    return dummy.next