天天看点

【LeetCode 08】206 反转链表

【LeetCode 08】206 反转链表

文章目录

  • ​​【LeetCode 08】206 反转链表​​
  • ​​一、题意​​
  • ​​二、思考过程​​

一、题意

【LeetCode 08】206 反转链表
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* reverseList(struct ListNode* head){
   
}       //返回3      

二、思考过程

struct ListNode* reverseList(struct ListNode* head){
   struct ListNode *tmp;
   struct ListNode *pre=NULL;
    while(head){
        tmp=head->next;
        head->next=pre;
        pre=head;
        head=tmp;
    }
    return pre;
}