/**
* 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) {
if(head==NULL || head->next==NULL){ //单节点和空节点情况
return head;
}
auto p = head;
auto q = head->next;
while(q){
auto o = q->next;
q->next = p;
p = q;
q = o;
}
head ->next = NULL; //需要手动修改第一个指针域
return p;
}
};