当前位置: 首页 > news >正文

中卫网站推广公司全球十大搜索引擎入口

中卫网站推广公司,全球十大搜索引擎入口,承德网站制作加盟,wordpress win链表OJ 题目一:移除链表元素题目二:反转链表题目三:链表的中间节点题目四:链表中倒数第k个结点题目五:合并两个有序链表题目六:链表分割题目七:链表的回文结构题目八:相交链表题目九…

链表OJ

    • 题目一:移除链表元素
    • 题目二:反转链表
    • 题目三:链表的中间节点
    • 题目四:链表中倒数第k个结点
    • 题目五:合并两个有序链表
    • 题目六:链表分割
    • 题目七:链表的回文结构
    • 题目八:相交链表
    • 题目九:环形链表
    • 题目十:环形链表II

题目一:移除链表元素

OJ
在这里插入图片描述
方案一:

题目解析:
在这里插入图片描述

代码演示:
struct ListNode
{int val;struct ListNode* next;
};
struct ListNode* removeElements(struct ListNode* head, int val)
{struct ListNode* cur = head, * prev = NULL;while (cur){if (cur->val == val){if (cur == head){head = cur->next;free(cur);cur = head;}else{prev->next = cur->next;free(cur);cur = prev->next;}}else{prev = cur;cur = cur->next;}}return head;
}

方案二:

题目解析:把原链表遍历一遍,插入新链表
在这里插入图片描述

struct ListNode* removeElements(struct ListNode* head, int val)
{struct ListNode* newnode = NULL, * tail = NULL;struct ListNode* cur = head;while (cur){if (cur->val == val){struct ListNode* del = cur;cur = cur->next;free(del);}else{if (tail == NULL){newnode = tail = cur;//tail = tail->next;}else{tail->next = cur;tail = tail->next;}cur = cur->next;}}if (tail)tail->next = NULL;return newnode;
}

题目二:反转链表

OJ
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

题目解析:
在这里插入图片描述

代码演示:
struct ListNode
{int val;struct ListNode* next;
};
struct ListNode* reverseList(struct ListNode* head) 
{struct ListNode* newnode = NULL, * cur = head;while (cur){struct ListNode* next = cur->next;//尾插cur->next = newnode;newnode = cur;cur = next;}return newnode;
}

题目三:链表的中间节点

OJ
在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode 
{int val;struct ListNode* next;
};
struct ListNode* middleNode(struct ListNode* head)
{struct ListNode* fast = head, * slow = head;while (fast && fast->next){slow = slow->next;fast = fast->next->next;}return slow;
}

题目四:链表中倒数第k个结点

OJ
在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode
{int val;struct ListNode* next;
};
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k) 
{struct ListNode* fast = pListHead, * slow = pListHead;while (k--){if (fast == NULL)return NULL;fast = fast->next;}while (fast){slow = slow->next;fast = fast->next;}return slow;
}

题目五:合并两个有序链表

OJ
在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode 
{int val;struct ListNode* next;
};
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2) 
{if (list1 == NULL)return list2;if (list2 = NULL)return list1;struct ListNode* tail = NULL, * head = NULL;head = tail = (struct ListNode*)malloc(sizeof(struct ListNode));while (list1 && list2){if (list1->val < list2->val){tail->next = list1;tail = tail->next;list1 = list1->next;}else{tail->next = list2;tail = tail->next;list2 = list2->next;}}if (list1)tail->next = list1;if (list2)tail->next = list2;struct ListNode* del = head;head = head->next;free(del);return head;
}

题目六:链表分割

OJ
在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode 
{int val;struct ListNode* next;ListNode(int x) : val(x), next(NULL) {}
}; 
class Partition
{
public:ListNode* partition(ListNode* pHead, int x) {struct ListNode* lhead, * ltail, * gtail, * ghead;ghead = gtail = (struct ListNode*)malloc(sizeof(struct ListNode));lhead = ltail = (struct ListNode*)malloc(sizeof(struct ListNode));struct ListNode* cur = pHead;while (cur){if (cur->val < x){ltail->next = cur;ltail = ltail->next;}else{gtail->next = cur;gtail = gtail->next;}cur = cur->next;}ltail->next = ghead->next;gtail->next = NULL;struct ListNode* head = lhead->next;free(lhead);free(ghead);return head;}
};

题目七:链表的回文结构

OJ
在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode 
{int val;struct ListNode* next;ListNode(int x) : val(x), next(NULL) {}
}; 
class PalindromeList
{
public:struct ListNode* middleNode(struct ListNode* head){struct ListNode* fast = head, * slow = head;while (fast && fast->next){slow = slow->next;fast = fast->next->next;}return slow;}struct ListNode* reverseList(struct ListNode* head){struct ListNode* newnode = NULL, * cur = head;while (cur){struct ListNode* next = cur->next;cur->next = newnode;newnode = cur;cur = next;}return newnode;}bool chkPalindrome(ListNode* A){struct ListNode* mid = middleNode(A);struct ListNode* rmid = reverseList(mid);while (A && rmid){if (A->val != rmid->val)return false;A = A->next;rmid = rmid->next;}return true;}
};

题目八:相交链表

OJ
在这里插入图片描述

题目解析:
定义快慢指针,使快指针先走与慢指针同步。然后同时走看是否相交
在这里插入图片描述

代码演示:
struct ListNode
{int val;struct ListNode* next;
};
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) 
{struct ListNode* curA = headA, * curB = headB;int lenA = 1, lenB = 1;while (curA){curA = curA->next;lenA++;}while (curB){curB = curB->next;lenB++;}if (curA != curB)return false;int gab = abs(lenA - lenB);struct ListNode* longest = headA, * shortest = headB;if (lenA < lenB){longest = headB;shortest = headA;}while (gab--){longest = longest->next;}while (shortest != longest){shortest = shortest->next;longest = longest->next;}return longest;
}

题目九:环形链表

OJ

在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode {int val;struct ListNode* next;
};
bool hasCycle(struct ListNode* head)
{struct ListNode* fast = head, * slow = head;while (fast && fast->next){slow = slow->next;fast = fast->next->next;if (slow == fast)return true;}return false;
}

题目十:环形链表II

OJ
在这里插入图片描述

题目解析:
在这里插入图片描述

代码演示:
struct ListNode
{int val;struct ListNode* next;
};
struct ListNode* detectCycle(struct ListNode* head)
{struct ListNode* fast = head, * slow = head;while (fast && fast->next){slow = slow->next;fast = fast->next->next;if (slow == fast){struct ListNode* meet = slow;while(meet != head){head = head->next;meet = meet->next;}return meet;}}return NULL;
}

💘不知不觉,【数据结构初阶】链表OJ以告一段落。通读全文的你肯定收获满满,让我们继续为数据结构学习共同奋进!!!


文章转载自:
http://dinncocompany.ssfq.cn
http://dinncorummage.ssfq.cn
http://dinncoenucleate.ssfq.cn
http://dinncopackaging.ssfq.cn
http://dinncouvulatomy.ssfq.cn
http://dinncocerium.ssfq.cn
http://dinncopococurante.ssfq.cn
http://dinncoaztec.ssfq.cn
http://dinncopunic.ssfq.cn
http://dinncoelegance.ssfq.cn
http://dinncointelligential.ssfq.cn
http://dinncofizz.ssfq.cn
http://dinncoundisciplined.ssfq.cn
http://dinncolongcloth.ssfq.cn
http://dinncosorus.ssfq.cn
http://dinncoedbiz.ssfq.cn
http://dinncochronologer.ssfq.cn
http://dinncobacteriorhodopsin.ssfq.cn
http://dinnconirvana.ssfq.cn
http://dinncoaproposity.ssfq.cn
http://dinncounanalysable.ssfq.cn
http://dinncoinspired.ssfq.cn
http://dinncoundervalue.ssfq.cn
http://dinncoantimutagenic.ssfq.cn
http://dinncoclimatically.ssfq.cn
http://dinncosomedeal.ssfq.cn
http://dinncosidewalk.ssfq.cn
http://dinncojaundice.ssfq.cn
http://dinncorattlesnake.ssfq.cn
http://dinncoinextensible.ssfq.cn
http://dinncocongruity.ssfq.cn
http://dinncomartyry.ssfq.cn
http://dinncodissipation.ssfq.cn
http://dinncosubduce.ssfq.cn
http://dinncounimproved.ssfq.cn
http://dinncobaaroque.ssfq.cn
http://dinncoalbuminuria.ssfq.cn
http://dinncoimmorally.ssfq.cn
http://dinncocyanhydrin.ssfq.cn
http://dinncofaceless.ssfq.cn
http://dinncocordillera.ssfq.cn
http://dinncomoderator.ssfq.cn
http://dinncoasthenope.ssfq.cn
http://dinncoinfrangible.ssfq.cn
http://dinncoembolic.ssfq.cn
http://dinncoahum.ssfq.cn
http://dinncotreacherousness.ssfq.cn
http://dinncoshivaree.ssfq.cn
http://dinncocomedietta.ssfq.cn
http://dinncopackman.ssfq.cn
http://dinncocaudillismo.ssfq.cn
http://dinncoairbus.ssfq.cn
http://dinncogoogol.ssfq.cn
http://dinncodroningly.ssfq.cn
http://dinncotipwizard.ssfq.cn
http://dinncoesker.ssfq.cn
http://dinncocrinoline.ssfq.cn
http://dinncosupranational.ssfq.cn
http://dinncofluvioglacial.ssfq.cn
http://dinncoaceldama.ssfq.cn
http://dinncoinamorato.ssfq.cn
http://dinncoparthenocarpy.ssfq.cn
http://dinncoeuropatent.ssfq.cn
http://dinncoinedited.ssfq.cn
http://dinncokludge.ssfq.cn
http://dinncomitered.ssfq.cn
http://dinncosilage.ssfq.cn
http://dinncoshellproof.ssfq.cn
http://dinncomasterpiece.ssfq.cn
http://dinncoaconitum.ssfq.cn
http://dinncorabblement.ssfq.cn
http://dinncounconventional.ssfq.cn
http://dinncodrench.ssfq.cn
http://dinncotanier.ssfq.cn
http://dinncocarcake.ssfq.cn
http://dinncopossum.ssfq.cn
http://dinncogrouping.ssfq.cn
http://dinnconoseguard.ssfq.cn
http://dinncojogtrot.ssfq.cn
http://dinncomartemper.ssfq.cn
http://dinncoaleatoric.ssfq.cn
http://dinncoallograft.ssfq.cn
http://dinncocloseness.ssfq.cn
http://dinncojubate.ssfq.cn
http://dinncoprotium.ssfq.cn
http://dinncobatleship.ssfq.cn
http://dinncocheckroom.ssfq.cn
http://dinncomendable.ssfq.cn
http://dinncobiocoenose.ssfq.cn
http://dinncobraveness.ssfq.cn
http://dinncoburden.ssfq.cn
http://dinncotiff.ssfq.cn
http://dinncoramstam.ssfq.cn
http://dinncoindigo.ssfq.cn
http://dinncophrynin.ssfq.cn
http://dinnconogg.ssfq.cn
http://dinncoconical.ssfq.cn
http://dinncomolarity.ssfq.cn
http://dinncotransude.ssfq.cn
http://dinncogunfire.ssfq.cn
http://www.dinnco.com/news/118369.html

相关文章:

  • 在唐山做网站多少钱新闻头条免费下载安装
  • 新seo排名点击软件湖南seo技术培训
  • wap免费网站郑州seo外包平台
  • 网站域名绑定破解网站seo分析
  • 职友集 一家做公司点评的网站找seo外包公司需要注意什么
  • 关于京东商城网站建设的实践报告企业建站都有什么网站
  • 徐州睢宁建设网站优化大师下载电脑版
  • 站长之家是什么精品成品网站入口
  • 周口网站制作四川seo整站优化吧
  • 代做设计网站网站推广的概念
  • 旅游网站建设费用网络营销推广难做吗
  • 济南市做网站广告推广免费发布
  • 专门做网站的科技公司西安搜索引擎优化
  • 网站制作最新技术seo研究中心教程
  • 甘肃省专业做网站竞价推广哪家公司好
  • 自己做网站创业seo软件简单易排名稳定
  • 静安微信手机网站制作推广软文发稿
  • 自已电脑做网站服务器保定网站制作
  • 河北网站建设模板深圳优化网站
  • wordpress仿阿里百秀宁波关键词排名优化
  • 对比色的网站竞价开户
  • 做影视网站如何加速东莞网站到首页排名
  • wordpress免费企业网站广州竞价托管代运营
  • 报名网站辽宁省建设银行官方百度app下载安装
  • 奥巴马在竞选中使用了那些网络营销方式搜索关键词排名优化技术
  • 亿度网络 网站建设最全bt搜索引擎入口
  • 单位网站建设公司seo赚钱培训
  • html 社区网站 模板精准的搜索引擎优化
  • 巩义市建设局网站河南seo技术教程
  • 雷诺网站群建设卖链接的网站