题目链接:https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/description/?favorite=xb9nqhhg
题目:
代码:
/**
* 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 *ans;
ans=NULL;
while(head!=NULL)
{
ListNode *tmp=head->next;
head->next=ans;
ans=head;
head=tmp;
}
return ans;
}
};