👉👉👉👉LeetCode刷题训练营👈👈👈👈
欢迎订阅本专栏,说在前面💖
今天给大家带来leetcode相关专栏习题的讲解!
博主为了本系列专栏,做了很多准备,争取图文并茂,让大家看明白!希望大家不要吝啬订阅,与关注,多多评论哦!!💖💖💖💖💖💖💖
一、前言
💪💪💪💪那么这里博主先安利一下其他一些干货满满的专栏啦!💪💪💪💪
玩转Linux操作系统+系统编程+网络编程,快速掌握数据结构宝藏文章,点击下方蓝字即可跳转:
🔝🔝🔝🔝🔝玩转Linux操作系统+系统编程+网络编程🔝🔝🔝🔝🔝
CCF相关真题,点击下方蓝字即可跳转:
🔝🔝🔝🔝🔝 CCF真题🔝🔝🔝🔝🔝
纵横数据结构与算法,点击下方蓝字跳转:
🔝🔝🔝🔝🔝数据结构与算法🔝🔝🔝🔝🔝
二 、正文
142. 环形链表 II
struct ListNode *detectCycle(struct ListNode *head) {
struct ListNode* fast =head;
struct ListNode* slow =head;
struct ListNode* meet =NULL;
struct ListNode* head2 =head;
while(fast && fast->next)
{
slow=slow->next;
fast=fast->next->next;
if(fast == slow)
{
meet = slow;
break;
}
}
if(meet == NULL)
{
return NULL;
}
while(head2 != meet)
{
head2=head2->next;
meet=meet->next;
}
return meet;
}
138. 复制带随机指针的链表
struct Node* copyRandomList(struct Node* head) {
struct Node* cur = head;
while(cur)
{
struct Node* copy = (struct Node*)malloc(sizeof(struct Node));
copy->val = cur->val;
copy->next = cur->next;
cur->next = copy;
cur = copy->next;
}
cur=head;
while(cur)
{
struct Node* copy =cur->next;
if(cur->random == NULL)
{
copy->random = NULL;
}
else{
copy->random = cur->random->next;
}
cur = copy->next;
}
cur = head;
struct Node* copyhead =NULL;
struct Node* copytail =NULL;
while(cur)
{
struct Node* copy =cur->next;
struct Node* tail =copy->next;
if(copyhead == NULL)
{
copyhead=copytail=copy;
}
else{
copytail->next=copy;
copytail=copytail->next;
}
cur->next = tail;
cur=tail;
}
return copyhead;
}
三、 结尾💖
🌹🌹🌹🌹🌹🌹🌹 感谢大家的点赞关注,希望大家多多评论!!!🌹🌹🌹🌹🌹🌹🌹