ACwing ACwing ACwing

ACwing ACwing ACwing,第1张

//DAY2.A

//题源:ACWING 反转链表

//参考:https://www.acwing.com/problem/content/33/

/**

 * Definition for singly-linked list.

 * struct ListNode {

 *     int val;

 *     ListNode *next;

 *     ListNode(int x) : val(x), next(NULL) {}

 * };

 */

class Solution {

public:

    ListNode* reverseList(ListNode* head) {

        ListNode*p=NULL;

        auto cur=head;

    while(cur)

    {

        auto next = cur -> next;

        cur -> next= p;

        p = cur;

        cur = next;

    }

    return p;

        

    }

};

考察知识点:数据结构 算法

单链表相关内容

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/915308.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-16
下一篇2022-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存