/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* ReverseList(ListNode* pHead) {
if(!pHead||!pHead->next) return pHead;
ListNode* pre=nullptr,*cur=pHead;
while(cur){
auto temp=cur->next;
cur->next=pre;
pre=cur;
cur=temp;
}
return pre;
}
};
NC78 反转链表(C++)- 简单、链表
最新推荐文章于 2023-10-25 00:44:34 发布