206. 反转链表C

/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head) {
if(!head) return NULL;
struct ListNode* t=head;
t=t->next;
head->next=NULL;
while(t){
struct ListNode* tem=t;
t=t->next;
tem->next=head;
head=tem;
}
return head;
}
结果:

浙公网安备 33010602011771号