1 /* 2 struct ListNode { 3 int val; 4 struct ListNode *next; 5 ListNode(int x) : 6 val(x), next(NULL) { 7 } 8 };*/ 9 class Solution { 10 public: 11 ListNode* ReverseList(ListNode* pHead) { 12 ListNode* res=NULL; 13 ListNode* pre=NULL; 14 if(pHead==NULL) return res; 15 while(pHead!=NULL){ 16 pre=pHead->next; 17 pHead->next=res; 18 res=pHead; 19 pHead=pre; 20 } 21 return res; 22 23 } 24 };
时间: 2024-10-07 05:31:52