206. 反转链表

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     struct ListNode *next;
 6  * };
 7  */
 8 
 9 
10 struct ListNode* reverseList(struct ListNode* head){
11     struct ListNode *new_head=NULL, *next;
12 
13     while (head) {
14         next = head->next;
15         head->next = new_head;
16         new_head = head;
17         head = next;
18     }
19     return new_head;
20 }

 

posted @ 2020-09-29 11:13  yushimeng  阅读(99)  评论(0编辑  收藏  举报