力扣206. 反转链表

206. 反转链表
在这里插入图片描述

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

//双指针算法
struct ListNode* reverseList(struct ListNode* head)
{
    
    
    struct ListNode* tmp;
    struct ListNode* prve=NULL;
    struct ListNode* cur=head;
    while(cur)
    {
    
    
        tmp=cur->next;
        cur->next=prve;
        prve=cur;
        cur=tmp;
    }
    return prve;
}

猜你喜欢

转载自blog.csdn.net/congfen214/article/details/129540581