剑指offer 反转链表

class Solution {
public:
    ListNode* ReverseList(ListNode* pHead) {
        ListNode* prev = nullptr;
        ListNode* curr = pHead;
        while ( curr != nullptr ){
            curr = pHead->next;
            pHead->next = prev;
            prev = pHead;
            pHead = curr;
        }
        return prev;
    }
};
posted @ 2018-08-25 19:05  一条图图犬  阅读(78)  评论(0编辑  收藏  举报