[LeetCode]206. Reverse Linked List

来源:互联网 发布:淘宝贷款不还会不会6 编辑:程序博客网 时间:2024/06/03 19:27

206. Reverse Linked List
Reverse a singly linked list.


/** * 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* pPre = NULL;        ListNode* pNext = NULL;        ListNode* pCur = head;        while(pCur){            pNext = pCur->next;            pCur->next = pPre;            pPre = pCur;            pCur = pNext;        }        return pPre;    }};
原创粉丝点击