1 /**
2 * Definition for singly-linked list.
3 * struct ListNode {
4 * int val;
5 * ListNode *next;
6 * ListNode(int x) : val(x), next(NULL) {}
7 * };
8 */
9 class Solution
10 {
11 public:
12 ListNode* reverseList(ListNode* head)
13 {
14 ListNode* new_head = NULL;
15 while(head)
16 {
17 ListNode* temp = head->next;
18 head->next = new_head;
19 new_head = head;
20 head = temp;
21 }
22 return new_head;
23 }
24 };
来源:https://www.cnblogs.com/yuhong1103/p/12547346.html