https://leetcode-cn.com/problems/reverse-linked-list/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* head) { ListNode * pre = NULL; ListNode * cur = head; ListNode * next = NULL; while(cur != NULL) { next = cur -> next; cur -> next = pre; //next -> next = cur; pre = cur; cur = next; } return pre; } };
|
Author:
Qin Peng
License:
Copyright (c) 2020 BY QPWLKQ LICENSE
Slogan:
每一个不曾起舞的日子, 都是对生命的辜负