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 节
全部评论
相关推荐
点赞 评论 收藏
分享


点赞 评论 收藏
分享