博客网站建设基本流程,wordpress怎么改cms,网站建设运营计划,php制作投票网站题目描述
给你单链表的头节点 head #xff0c;请你反转链表#xff0c;并返回反转后的链表。
出处
思路
经典考研题#xff0c;用头插法解决。
代码
class Solution {
public:ListNode* reverseList(ListNode* head) {if(!head || !head-next) return head;List…题目描述
给你单链表的头节点 head 请你反转链表并返回反转后的链表。
出处
思路
经典考研题用头插法解决。
代码
class Solution {
public:ListNode* reverseList(ListNode* head) {if(!head || !head-next) return head;ListNode* p1head;ListNode* p2head-next;ListNode* p3head;p1-nextnullptr;while(p2!nullptr){p1p2;p2p2-next;p1-nextp3;p3p1;}return p3;}
};