15:反转链表

2019-08-06  本文已影响0人  iwtbam

题目描述

解题思路

AC代码

class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
        
        ListNode* pre = nullptr;
        ListNode* cur = pHead;
        while(cur)
        {
            ListNode* next = cur->next;
            cur->next = pre;
            pre = cur;
            cur = next;
        }
        
        return pre;
    }
};

上一篇 下一篇

猜你喜欢

热点阅读