JZ24 反转链表
//实现
//My code
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
struct ListNode *head = pHead->next; //指向第二个节点
struct ListNode *temp; //中间变量
pHead->next = NULL; //先让第一个跟第二个断开
while(head->next != NULL)
{
temp = head;//把该节点复制给中间变量
head = head->next;//再指向第三个节点
temp->next = pHead;//第二个节点指向第一个节点
pHead = temp;//头节点为原来第二个节点
}
head->next = temp;//第三个指向第二个
return head;
}
终于会了
//实现
//My code
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
struct ListNode *head = pHead->next; //指向第二个节点
struct ListNode *temp; //中间变量
pHead->next = NULL; //先让第一个跟第二个断开
while(head->next != NULL)
{
temp = head;//把该节点复制给中间变量
head = head->next;//再指向第三个节点
temp->next = pHead;//第二个节点指向第一个节点
pHead = temp;//头节点为原来第二个节点
}
head->next = temp;//第三个指向第二个
return head;
}
终于会了
2021-10-19
在牛客打卡1天,今天学习:刷题 2 道/代码提交 9 次/学习课程 1 节
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
专业嗎喽:硕佬,把学校背景放后面几段,学校背景双非还学院,让人看了就不想往下看。
把实习经历和个人奖项放前面,用数字化简述自己实习的成果和掌握的技能,比如负责项目一次通过率90%,曾4次发现项目潜在问题风险为公司减少损失等等 点赞 评论 收藏
分享
2025-11-15 13:39
西安电子科技大学 C++ 点赞 评论 收藏
分享