牛客-反轉鏈表
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if (pHead == NULL) return NULL;
ListNode *cur, *p=NULL, *temp;
cur = pHead;
while(pHead->next!=NULL) {
temp = cur->next;
cur->next = p;
p=cur;
cur=temp;
pHead=temp;
}
cur->next=p;
return cur;
}
};