[leetcode]206.反转单链表(Reverse Linked List )C++代码实现

    xiaoxiao2022-07-12  149

    1,题目描述

    2,题目分析

    参考博客:https://blog.csdn.net/qq_17550379/article/details/80647926

    3,代码实现

    /** * 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* pre = nullptr; ListNode* cur = head; while (cur != nullptr) { ListNode* lat = cur->next; cur->next = pre; pre = cur; cur = lat; } return pre; } };

     

    最新回复(0)