/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if(pHead == NULL || pHead->next == NULL)
return pHead;
ListNode *p = pHead;
ListNode *q = p->next;
ListNode *s = NULL;
pHead ->next = NULL;
while(q != NULL)
{
s = q->next;
q->next = p;
p = q;
q = s;
}
pHead = p;
return pHead;
}
};
单链表反转
最新推荐文章于 2021-08-05 17:26:36 发布