2- Reverse linked list (first phone interview)
Anonymous
struct ListNode { int val; ListNode *next; ListNode (int v):val(v),next(NULL){} }; ListNode *reverseList(ListNode *head) { if(NULL==head || NULL==head->next) return head; ListNode *cur=head,*pre=NULL; while(cur) { ListNode *tmp=cur->next; cur->next=pre; pre=cur; cur=tmp; } return pre; }
Check out your Company Bowl for anonymous work chats.