//in place and in one pass
ListNode *reverse(ListNode *head) {
if (!head) return head;
ListNode dummy(0);
dummy.next = head;
ListNode *p = &dummy;
while(head->next) {
ListNode *T = head->next;
head->next = T->next;
T->next = p->next;
p->next = T;
}
return dummy.next;
}