## Update 4:

"Code golf" (6 lines)

Not fully golfed, but yeah...

```
ListNode* reverseBetween(ListNode *head, int m, int n) {
ListNode **a = &head, **b;
for (;m--; n--)
a = &(*(b=a))->next;
for (;n--; swap(*b, *a))
swap(*b, (*a)->next);
return head;
}
```

## Update 3:

Pointer pointers (8 lines)

Removed duplicate code.

```
ListNode* reverseBetween(ListNode *head, int m, int n) {
ListNode **pivot = &head, **prev;
for (int i=0; i<m; i++)
pivot = &(*(prev=pivot))->next;
for (int i=m; i<n; i++) {
swap(*prev, (*pivot)->next);
swap(*prev, *pivot);
}
return head;
}
```

## Update 2:

Pointer pointers (9 lines)

Using a second pointer pointer.

```
ListNode* reverseBetween(ListNode *head, int m, int n) {
ListNode **prev = &head;
for (int i=1; i<m; i++)
prev = &(*prev)->next;
ListNode **pivot = &(*prev)->next;
for (int i=m; i<n; i++) {
swap(*prev, (*pivot)->next);
swap(*prev, *pivot);
}
return head;
}
```

## Update 1:

Pointer pointer (9 lines)

Motivated by quick glance at lchen77's solution.

```
ListNode* reverseBetween(ListNode *head, int m, int n) {
ListNode **prev = &head;
for (int i=1; i<m; i++)
prev = &(*prev)->next;
ListNode *pivot = *prev;
for (int i=m; i<n; i++) {
swap(*prev, pivot->next->next);
swap(*prev, pivot->next);
}
return head;
}
```

## Dummy node (10 lines)

My original one.

```
ListNode* reverseBetween(ListNode *head, int m, int n) {
ListNode dummy(0), *prev = &dummy;
dummy.next = head;
for (int i=1; i<m; i++)
prev = prev->next;
ListNode *pivot = prev->next;
for (int i=m; i<n; i++) {
swap(prev->next, pivot->next->next);
swap(prev->next, pivot->next);
}
return dummy.next;
}
```