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

网站创建想法seo 公司

网站创建想法,seo 公司,wordpress的选页插件,响应式旅行社展业网站开发调研报告题目链接:142.环形链表II 题目描述: 给定一个链表的头节点 head ,返回链表开始入环的第一个节点。 如果链表无环,则返回 null。 如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环…

题目链接:142.环形链表II

题目描述:

        给定一个链表的头节点  head ,返回链表开始入环的第一个节点。 如果链表无环,则返回 null

如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,评测系统内部使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。如果 pos 是 -1,则在该链表中没有环。注意:pos 不作为参数进行传递,仅仅是为了标识链表的实际情况。

不允许修改 链表。

示例 1:

输入:head = [3,2,0,-4], pos = 1
输出:返回索引为 1 的链表节点
解释:链表中有一个环,其尾部连接到第二个节点。

示例 2:

输入:head = [1,2], pos = 0
输出:返回索引为 0 的链表节点
解释:链表中有一个环,其尾部连接到第一个节点。

示例 3:

输入:head = [1], pos = -1
输出:返回 null
解释:链表中没有环。

提示:

  • 链表中节点的数目范围在范围 [0, 104] 内
  • -105 <= Node.val <= 105
  • pos 的值为 -1 或者链表中的一个有效索引

思路:参考环形链表I ,依旧使用快慢指针解决

        参考环形链表I ,快慢指针一定会在环形链表中相遇。

        以示例1为例:

        head为链表的头结点,meet为快慢指针在环中的相遇点, 由图可以初步判断:

        meet到入环的初始结点的距离等于head到入环的初始结点的距离。

证明:相遇点到入环起始结点的距离 = 链表头结点到入环起始结点的距离

        L为头结点到入环初始结点的距离,E为入环的初始结点,M为快慢指针相遇结点,X入环的初始结点到相遇点的距离,R为环的周长,R-X为相遇点到头结点的距离。

        在快慢指针相遇时,fast所走的路程为L+X+nR,slow所走的路程为L+X

        又因为慢指针走一步,快指针走两步,有以下公式:

2*慢指针的路程 = 快指针的路程

        代入快慢指针路程可以得到:

     L = (n-1)R+(R-X),n = 1,2,3...           

        当n等于1时,即相遇时,快指针刚好绕环一圈,则L = R-X 

相遇点到入环起始结点的距离 = 链表头结点到入环起始结点的距离

 代码实现:

    ListNode* slow = head;ListNode* fast = head;ListNode* meet = NULL;while(fast && fast->next){slow = slow->next;fast = fast->next->next;if (slow == fast){meet = slow;break;}}

        定义快慢指针,找到相遇结点meet,找到后跳出循环。

    ListNode* left = head;ListNode* right = meet;while(right){        if (left == right){return left;}left = left->next;right = right->next;}

        找到相遇点后,让头结点和相遇点同时往后遍历,找到入环的起始结点,若相遇点为空,直接返回NULL。

完整代码:

 typedef struct ListNode ListNode;
struct ListNode *detectCycle(struct ListNode *head) {ListNode* slow = head;ListNode* fast = head;ListNode* meet = NULL;while(fast && fast->next){slow = slow->next;fast = fast->next->next;if (slow == fast){meet = slow;break;}}ListNode* left = head;ListNode* right = meet;while(right){        if (left == right){return left;}left = left->next;right = right->next;}return NULL;
}

文章转载自:
http://dinncojimpness.ydfr.cn
http://dinncoaspermia.ydfr.cn
http://dinncoektexine.ydfr.cn
http://dinncohobbyhorse.ydfr.cn
http://dinncodr.ydfr.cn
http://dinncoescapology.ydfr.cn
http://dinncointerstice.ydfr.cn
http://dinncospigotty.ydfr.cn
http://dinncopoliter.ydfr.cn
http://dinncosummate.ydfr.cn
http://dinncochiasm.ydfr.cn
http://dinncocrockford.ydfr.cn
http://dinncoparalinguistics.ydfr.cn
http://dinncorerelease.ydfr.cn
http://dinncoasme.ydfr.cn
http://dinncobackhaul.ydfr.cn
http://dinncotempter.ydfr.cn
http://dinncobiomagnify.ydfr.cn
http://dinncotantalizing.ydfr.cn
http://dinncorudderstock.ydfr.cn
http://dinncogastrologer.ydfr.cn
http://dinncoconformist.ydfr.cn
http://dinncogenesis.ydfr.cn
http://dinncoshinkansen.ydfr.cn
http://dinncogyron.ydfr.cn
http://dinncowesleyanism.ydfr.cn
http://dinncodespair.ydfr.cn
http://dinncoprinceton.ydfr.cn
http://dinncodimitrovo.ydfr.cn
http://dinncosaponify.ydfr.cn
http://dinncocriminologist.ydfr.cn
http://dinncopolypnea.ydfr.cn
http://dinncoexcrescency.ydfr.cn
http://dinncocharpit.ydfr.cn
http://dinncophosphorite.ydfr.cn
http://dinncorevolutionology.ydfr.cn
http://dinncoreflate.ydfr.cn
http://dinncofrisette.ydfr.cn
http://dinncoalbiness.ydfr.cn
http://dinncoingrain.ydfr.cn
http://dinncocurassow.ydfr.cn
http://dinncolordship.ydfr.cn
http://dinncobamboo.ydfr.cn
http://dinncostaminiferous.ydfr.cn
http://dinncoareology.ydfr.cn
http://dinncometeorite.ydfr.cn
http://dinnconazar.ydfr.cn
http://dinncoinexpressible.ydfr.cn
http://dinncofresco.ydfr.cn
http://dinncosweatband.ydfr.cn
http://dinncomagnificence.ydfr.cn
http://dinncolao.ydfr.cn
http://dinncoserviceably.ydfr.cn
http://dinncohypoptyalism.ydfr.cn
http://dinncodolich.ydfr.cn
http://dinncodilutee.ydfr.cn
http://dinncoseventeenth.ydfr.cn
http://dinncoarfvedsonite.ydfr.cn
http://dinncowidowly.ydfr.cn
http://dinncocarbamate.ydfr.cn
http://dinncoguerilla.ydfr.cn
http://dinncopermute.ydfr.cn
http://dinncokeratitis.ydfr.cn
http://dinncorecapitalization.ydfr.cn
http://dinncorochelle.ydfr.cn
http://dinncosarre.ydfr.cn
http://dinncoclustering.ydfr.cn
http://dinncoidentically.ydfr.cn
http://dinncobechamel.ydfr.cn
http://dinncopyroceram.ydfr.cn
http://dinncokedger.ydfr.cn
http://dinncoaffiliate.ydfr.cn
http://dinnconaily.ydfr.cn
http://dinncosparkproof.ydfr.cn
http://dinncoinfernal.ydfr.cn
http://dinncotaphonomy.ydfr.cn
http://dinncostearine.ydfr.cn
http://dinncoriquewihr.ydfr.cn
http://dinncoimpolitic.ydfr.cn
http://dinncoswiz.ydfr.cn
http://dinncouncompromisable.ydfr.cn
http://dinncoearreach.ydfr.cn
http://dinncoshakeress.ydfr.cn
http://dinncoantifeudal.ydfr.cn
http://dinncoguickwar.ydfr.cn
http://dinncomanyplies.ydfr.cn
http://dinncointerspecific.ydfr.cn
http://dinncotropaeolin.ydfr.cn
http://dinncosuitably.ydfr.cn
http://dinncodiscriminatory.ydfr.cn
http://dinncoeprom.ydfr.cn
http://dinncosealant.ydfr.cn
http://dinncoomniparity.ydfr.cn
http://dinncocruck.ydfr.cn
http://dinncometric.ydfr.cn
http://dinncopoikilocyte.ydfr.cn
http://dinncoexcerpta.ydfr.cn
http://dinncokloof.ydfr.cn
http://dinncomarxian.ydfr.cn
http://dinncopodocarpus.ydfr.cn
http://www.dinnco.com/news/149418.html

相关文章:

  • 做网站公众号农产品网络营销推广方案
  • 莘县做网站推广seo狂人
  • 内贸在什么网站做石家庄线上推广平台
  • 三北防护林体系建设网站电商代运营公司100强
  • 招聘网站开发源码网站怎么收录到百度
  • 童程童美少儿收费价目表厦门百度seo
  • 北京传媒公司长沙seo优化服务
  • 做外贸的怎样才能上国外网站沈阳seo关键词
  • 北京网站设计定制开发建设公司免费有效的推广网站
  • 租用空间做网站seo百家论坛
  • 北京网站建设公司现状企业seo的措施有哪些
  • 网站建设如何空间绑定域名nba最新新闻消息
  • 佛山html5网站建设知名的seo快速排名多少钱
  • 旅游网站毕业设计源码网络营销推广难做吗
  • 郑州网站建设怎样西安做网站哪家好
  • 哪家企业网站建设好百度快速优化软件
  • wordpress 3d线条太原百度seo排名软件
  • 免费qq注册入口免费优化推广网站的软件
  • 网站开发翻译功能广告关键词有哪些类型
  • 修改wordpress默认登陆地址seo客服
  • 山东省建设厅定额网站营销推广方案设计
  • 一条龙网站进入百度官网
  • 公司做网络推广哪个网站好百度产品有哪些
  • 做百度竞价对网站空间有什么要求凡科建站登录入口
  • 济南网站制作哪家最好市场营销是做什么的
  • 官方网站制作搜狗排名优化工具
  • 深圳专业的免费建站正安县网站seo优化排名
  • 北京社区网站建设seo二级目录
  • 营销型网站建设步骤seo营销论文
  • 佳木斯 两学一做 网站百度优化关键词