题目链接: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;
}
};
该问题是一个编程挑战,要求实现一个函数,接收一个单链表的头节点,然后反转链表。代码示例中提供了一个C++的解决方案,使用迭代方式完成链表的反转。
666

被折叠的 条评论
为什么被折叠?



