/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
if(pHead==NULL)
return NULL;
struct ListNode*cur = pHead;
struct ListNode*newhead = NULL;
while(cur)
{
struct ListNode*next = cur->next;
//头插
cur->next = newhead;
newhead = cur;
//迭代往后走
cur = next;
}
return newhead;
}

京公网安备 11010502036488号