反转链表
主要思路是定义两个指向结点的指针
/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* ReverseList(ListNode* pHead) { ListNode* pre=NULL; while(pHead!=NULL){ ListNode* Next=pHead->next; pHead->next=pre; pre=pHead; pHead=Next; } return pre; } };

浙公网安备 33010602011771号