//DAY2.A
//题源:ACWING 反转链表
//参考:/problem/content/33/
/**
* 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*p=NULL;
auto cur=head;
while(cur)
{
auto next = cur -> next;
cur -> next= p;
p = cur;
cur = next;
}
return p;
}
};
考察知识点:数据结构 算法
单链表相关内容