标签:
<pre name="code" class="cpp">/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */
ListNode* reverseList(ListNode* head) { if(!head) return head; ListNode* p=head; ListNode* q=p->next; if(!q) return head; ListNode* k=q->next; p->next=NULL; while(k) { q->next=p; p=q; q=k; k=k->next; } q->next=p; return q;//返回头结点 }
leetCode(1):Reverse Linked List
标签:
原文地址:http://blog.csdn.net/walker19900515/article/details/46518015