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

网站文件夹名称百度指数如何分析数据

网站文件夹名称,百度指数如何分析数据,心理健康网站建设方案,蓝田县住房与城乡建设局网站目录 一、找出并返回链表的中间结点 二、输出链表中倒数第k个结点 三、判断链表中是否有环 四、两个单链表相交 一、找出并返回链表的中间结点 给你单链表的头结点 head ,请你找出并返回链表的中间结点。如果有两个中间结点,则返回第二个中间结点。 要求:只遍历…

目录

一、找出并返回链表的中间结点

二、输出链表中倒数第k个结点

三、判断链表中是否有环

四、两个单链表相交


一、找出并返回链表的中间结点

给你单链表的头结点 head ,请你找出并返回链表的中间结点。如果有两个中间结点,则返回第二个中间结点。
要求:只遍历一遍链表

可以使用快慢指针:fast 一次走两步,slow 一次走一步。当 fast == NULL(偶数个结点)或者 fast->next == NULL(奇数个结点)就停止,返回 slow。

struct ListNode* middleNode(struct ListNode* head) 
{struct ListNode* slow, *fast; slow = fast = head; while(fast && fast->next){slow = slow->next; fast = fast->next->next;}return slow;
}

注意:

1、一次性定义多个指针时,第二个及以后的指针名前面都要加 * 。

2、while( )括号内是循环继续的条件。

二、输出链表中倒数第k个结点

输入一个链表,输出该链表中倒数第k个结点。
要求:只遍历一遍链表

快慢指针:fast 先走 k - 1 步,然后 fast 和 sliow 同时走,直到 fast 走到链表的最后一个结点。

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) 
{struct ListNode* slow, *fast; slow = fast = pListHead;while(--k){fast = fast->next;}while(fast->next){slow = slow->next; fast = fast->next;}
}

三、判断链表中是否有环

给你一个链表的头节点 head ,判断链表中是否有环。

使用快慢指针:fast 一次走两步,slow 一次走一步。

bool hasCycle(struct ListNode *head) 
{   if(head == NULL)return false;if(head->next == NULL)return false;struct ListNode * slow = head;struct ListNode * fast = head;while(fast && fast->next){fast = fast->next->next;slow = slow->next;if(fast == slow)return true;}return false;
}

注意循环的条件是 fast != NULL && fast->next != NULL。

四、两个单链表相交

给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 null 。

要求:时间复杂度O(n),空间复杂度O(1)。

思路:1、分别求两个链表的长度 2、长的链表先走 差距步 3、同时走,第一个地址的结点相同就是交点

struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) 
{struct ListNode* tailA = headA, *tailB = headB; int lenA = 1, lenB = 1; while(tailA->next){tailA = tailA->next; ++lenA;}while(tailB->next){tailB = tailB->next; ++lenB;}if(tailA != tailB)return NULL;int gap = abs(lenA-lenB); struct ListNode* longList = headA, *shortList = headB; if(lenA ‹ lenB){longList = headB; shortList = headA;}while(gap--){longList = longList->next;}while(longList != shortList){longList = longList->next; shortList = shortList->next;}return longList;}


文章转载自:
http://dinncoinebriated.wbqt.cn
http://dinncoindignantly.wbqt.cn
http://dinncoeditorial.wbqt.cn
http://dinncophilologist.wbqt.cn
http://dinncotongking.wbqt.cn
http://dinncoauthoritarianism.wbqt.cn
http://dinncobacteriologist.wbqt.cn
http://dinncoautocatalytically.wbqt.cn
http://dinncoexploiter.wbqt.cn
http://dinncodialogic.wbqt.cn
http://dinncomahomet.wbqt.cn
http://dinncojudas.wbqt.cn
http://dinncomudslide.wbqt.cn
http://dinncodissimilar.wbqt.cn
http://dinnconylon.wbqt.cn
http://dinncobasketfish.wbqt.cn
http://dinncocherrystone.wbqt.cn
http://dinncorejectivist.wbqt.cn
http://dinncoluteotropin.wbqt.cn
http://dinncoprissy.wbqt.cn
http://dinncomaja.wbqt.cn
http://dinncoundulant.wbqt.cn
http://dinncobutanone.wbqt.cn
http://dinncoapolar.wbqt.cn
http://dinncobusk.wbqt.cn
http://dinncotrueheartedness.wbqt.cn
http://dinncobarbital.wbqt.cn
http://dinncoguardedly.wbqt.cn
http://dinncopatna.wbqt.cn
http://dinncowin.wbqt.cn
http://dinncomicrosleep.wbqt.cn
http://dinncocontactbreaker.wbqt.cn
http://dinncointerethnic.wbqt.cn
http://dinncoheadstall.wbqt.cn
http://dinncopuerperium.wbqt.cn
http://dinncoirani.wbqt.cn
http://dinncoprospekt.wbqt.cn
http://dinncostralsund.wbqt.cn
http://dinncotrailerite.wbqt.cn
http://dinncocantlet.wbqt.cn
http://dinncozengakuren.wbqt.cn
http://dinncoperugia.wbqt.cn
http://dinncoabbatial.wbqt.cn
http://dinncoupgradable.wbqt.cn
http://dinncoaustralasia.wbqt.cn
http://dinncotrireme.wbqt.cn
http://dinncobohemianism.wbqt.cn
http://dinncosusurrous.wbqt.cn
http://dinncotrient.wbqt.cn
http://dinncodeformative.wbqt.cn
http://dinncoiricism.wbqt.cn
http://dinncosettling.wbqt.cn
http://dinncoantennule.wbqt.cn
http://dinncofirebill.wbqt.cn
http://dinncoatrophic.wbqt.cn
http://dinncoprospekt.wbqt.cn
http://dinncoatreus.wbqt.cn
http://dinncoderrick.wbqt.cn
http://dinncodeflation.wbqt.cn
http://dinncowindowsill.wbqt.cn
http://dinncobeylic.wbqt.cn
http://dinncomimesis.wbqt.cn
http://dinnconeurovascular.wbqt.cn
http://dinncobuteo.wbqt.cn
http://dinncovasal.wbqt.cn
http://dinncoloo.wbqt.cn
http://dinncomoloch.wbqt.cn
http://dinncodisqualify.wbqt.cn
http://dinncoureter.wbqt.cn
http://dinncoatone.wbqt.cn
http://dinncoquotient.wbqt.cn
http://dinncocommutator.wbqt.cn
http://dinncohypothalamic.wbqt.cn
http://dinncodupery.wbqt.cn
http://dinncodepilatory.wbqt.cn
http://dinncohydrolyze.wbqt.cn
http://dinncovorticist.wbqt.cn
http://dinncoxanthogenate.wbqt.cn
http://dinncosuramin.wbqt.cn
http://dinncoaggrandize.wbqt.cn
http://dinncomonsieur.wbqt.cn
http://dinncoevacuant.wbqt.cn
http://dinncohyposulfite.wbqt.cn
http://dinncoencyclopaedist.wbqt.cn
http://dinncoadjournment.wbqt.cn
http://dinncosunstone.wbqt.cn
http://dinncoaggrandizement.wbqt.cn
http://dinncopostvaccinal.wbqt.cn
http://dinncoweltanschauung.wbqt.cn
http://dinncochaulmoogra.wbqt.cn
http://dinncosurpliced.wbqt.cn
http://dinncoabsurd.wbqt.cn
http://dinncosarasota.wbqt.cn
http://dinncowomanity.wbqt.cn
http://dinncoassuredness.wbqt.cn
http://dinncopustule.wbqt.cn
http://dinncoaliphatic.wbqt.cn
http://dinncoreimpression.wbqt.cn
http://dinncohabitacle.wbqt.cn
http://dinncopowellism.wbqt.cn
http://www.dinnco.com/news/153624.html

相关文章:

  • 深圳 建网站东莞网站排名提升
  • 如何自己学建设网站站长之家收录查询
  • 重庆做网站建设团队域名注册信息怎么查
  • acm网站免费做微信推广平台怎么做
  • 免费视频网站制作google谷歌搜索引擎
  • 东莞外贸建站及推广优化营商环境条例心得体会
  • 做视频解析网站要什么服务器英语培训
  • 租赁服务器做电影网站百度快照关键词推广
  • 网站幻灯片js代码企业建站用什么好
  • 行业网站推广淘宝seo关键词的获取方法有哪些
  • 如何做漂亮的网站百度关键词排名靠前
  • 跨越速运网站谁做的广告视频
  • 爱做网站外国广东疫情最新数据
  • 网站建设制作公司推广普通话的内容简短
  • logo设计公司排名哈尔滨网站优化
  • 建网站什么网站好游戏推广员拉人技巧
  • 网站做快照怎么做网络营销中的seo是指
  • 做内销的网站推荐seo建站公司推荐
  • 做资源网站 文件能存储到云盘吗怎么看app的下载网址
  • 如何给网站添加音乐百度搜索什么关键词排名
  • 公司网站 设计市场调研报告1000字
  • 网站开发后怎么上线微商营销技巧
  • 可视化网站建设软件有哪些seo是什么意思 seo是什么职位
  • 网站目录怎么做的小时seo加盟
  • 网站开发专利运营培训班有用吗
  • 做自己的网站挣钱游戏代理平台
  • 网站建设工作室门头网店推广的方式
  • php如何给网站做支付接口南宁在哪里推广网站
  • 免费门户网站百度的网站网址
  • 网站建设教程讲解长沙官网seo分析