ListNode* reverseList(ListNode* head) {ListNode* t1,*t2,*t3; t1 = head; if(head!=NULL) t2 = head->next; else return head; if(t2!=NULL) t3 = head->next->next; else { return head; } head->next=NULL; while(t3!=NULL) { t2->next=t1; t1=t2; t2=t3; t3=t3->next; } t2->next=t1; head = t2; return head; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter