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* p = pHead; 13 ListNode* q = NULL; 14 ListNode* r = NULL; 15 while(p != NULL){ 16 r = p->next; 17 p->next = q; 18 q = p; 19 p = r; 20 } 21 return q; 22 } 23 };
时间: 2024-10-12 16:54:16