反转链表

/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* ReverseList(ListNode* pHead) { ListNode* cur=pHead; ListNode* pre=nullptr; ListNode* nex=nullptr; while(cur){ nex=cur->next; cur->next=pre; pre=cur; cur=nex; } return pre; } };
浙公网安备 33010602011771号