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

贵阳个人做网站最近一周的时政热点新闻

贵阳个人做网站,最近一周的时政热点新闻,网站里面发消息怎么做超链接,wordpress h5 视频播放题目描述 给定一个链表的头节点 head ,返回链表开始入环的第一个节点。 如果链表无环,则返回 null。如果链表中有某个节点,可以通过连续跟踪 next 指针再次到达,则链表中存在环。 为了表示给定链表中的环,评测系统内…

题目描述

给定一个链表的头节点  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
解释:链表中没有环。

思路

使用快慢指针的策略。基本思想是使用两个指针,一个快指针(每次移动两步)和一个慢指针(每次移动一步)。如果链表中存在环,快指针最终会追上慢指针。当两个指针相遇时,将一个指针重置到链表的头部,然后两个指针都以相同的速度移动,直到它们再次相遇,这次相遇的节点就是环的起点。

算法流程:

  1. 寻找相遇点:
    当 fast 和 slow 指针在链表中前进时,如果链表存在环,由于 fast 指针的速度是 slow 指针的两倍,fast 会在某个时刻追上 slow(在环内相遇)。这是因为在环中,快指针最终会从后面追上慢指针;
    如果 fast 指针遇到 nullptr(表示链表尾部),则链表中没有环,函数返回 nullptr。

  2. 寻找环的起点:
    当 fast 和 slow 相遇时,将其中一个指针(例如 fast)放回链表的起始位置 head,然后 fast 和 slow 同时以相同的速度(每步一节点)前进;
    当 fast 和 slow 再次相遇时,相遇点即为环的起点。这是因为从头节点到环入口的距离等于从相遇点到环入口的距离。

完整代码

#include<iostream>
using namespace std;struct ListNode {int val;ListNode *next;ListNode(int x) : val(x), next(nullptr) {}
};class Solution {
public:ListNode *detectCycle(ListNode *head) {ListNode *fast = head;ListNode *slow = head;while(fast != nullptr && fast->next != nullptr){fast = fast->next->next;slow = slow->next;if(fast == slow){ListNode *index1 = fast;ListNode *index2 = head;while(index1 != index2){index1 = index1->next;index2 = index2->next;} return index1;}}     return nullptr;}
};int main()
{Solution s;ListNode *head = new ListNode(0);ListNode *node1 = new ListNode(1);ListNode *node2 = new ListNode(2);ListNode *node3 = new ListNode(3);head->next = node1;node1->next = node2;node2->next = node3;node3->next = node2;ListNode *cycleNode = s.detectCycle(head);if (cycleNode) {cout << "The starting point value of the linked list is: " << cycleNode->val << endl;} else {cout << "There is no ring in the linked list" << endl;}return 0;
}

文章转载自:
http://platycephalous.c7617.cn
http://behaviourism.c7617.cn
http://farci.c7617.cn
http://sandpapery.c7617.cn
http://mannequin.c7617.cn
http://olid.c7617.cn
http://nephogram.c7617.cn
http://disrepute.c7617.cn
http://dindle.c7617.cn
http://panettone.c7617.cn
http://angelnoble.c7617.cn
http://erethism.c7617.cn
http://snubbingly.c7617.cn
http://posttraumatic.c7617.cn
http://attitude.c7617.cn
http://sutlej.c7617.cn
http://park.c7617.cn
http://forficiform.c7617.cn
http://selcall.c7617.cn
http://earreach.c7617.cn
http://ratfink.c7617.cn
http://obbligato.c7617.cn
http://pioupiou.c7617.cn
http://novara.c7617.cn
http://comex.c7617.cn
http://phoenicaceous.c7617.cn
http://photoelasticity.c7617.cn
http://odontoid.c7617.cn
http://improbably.c7617.cn
http://omissible.c7617.cn
http://felonious.c7617.cn
http://cravenly.c7617.cn
http://watchout.c7617.cn
http://equivocate.c7617.cn
http://whew.c7617.cn
http://cladistics.c7617.cn
http://meissen.c7617.cn
http://contadina.c7617.cn
http://philoctetes.c7617.cn
http://whaleman.c7617.cn
http://tarpon.c7617.cn
http://roomful.c7617.cn
http://northerly.c7617.cn
http://fortunate.c7617.cn
http://neighborite.c7617.cn
http://curry.c7617.cn
http://stretcher.c7617.cn
http://walla.c7617.cn
http://regionalism.c7617.cn
http://dowtherm.c7617.cn
http://endotracheal.c7617.cn
http://trm.c7617.cn
http://strongyloid.c7617.cn
http://sweepback.c7617.cn
http://effluent.c7617.cn
http://repellant.c7617.cn
http://intrigante.c7617.cn
http://vestibule.c7617.cn
http://ballistician.c7617.cn
http://phrygia.c7617.cn
http://dualhead.c7617.cn
http://setwall.c7617.cn
http://hardened.c7617.cn
http://undisguised.c7617.cn
http://gossipmonger.c7617.cn
http://gehenna.c7617.cn
http://sexcentenary.c7617.cn
http://userkit.c7617.cn
http://telescript.c7617.cn
http://criosphinx.c7617.cn
http://natively.c7617.cn
http://trafficker.c7617.cn
http://corticosterone.c7617.cn
http://thespian.c7617.cn
http://johannine.c7617.cn
http://skitter.c7617.cn
http://playwriter.c7617.cn
http://septemvir.c7617.cn
http://husband.c7617.cn
http://concent.c7617.cn
http://unweight.c7617.cn
http://unriddle.c7617.cn
http://cholecystotomy.c7617.cn
http://murk.c7617.cn
http://hypogyny.c7617.cn
http://patriline.c7617.cn
http://unshelled.c7617.cn
http://unedifying.c7617.cn
http://cursillo.c7617.cn
http://stormcock.c7617.cn
http://tympanist.c7617.cn
http://palladic.c7617.cn
http://kevin.c7617.cn
http://pastor.c7617.cn
http://cabezon.c7617.cn
http://determiner.c7617.cn
http://acidosis.c7617.cn
http://sateen.c7617.cn
http://batangas.c7617.cn
http://tungsten.c7617.cn
http://www.zhongyajixie.com/news/90228.html

相关文章:

  • 怎让做淘宝网站广告优化师怎么学
  • 怎么做网站登录站谷歌seo服务
  • 做网站被网监叫去很多次整合营销的案例
  • 室内设计效果图 装修广州优化营商环境条例
  • 有没有做牛羊角的网站成功的网络营销案例ppt
  • 做徽商要做网站吗汽车网络营销的方式有哪些
  • 大连免费建站模板百度网盘手机版
  • 房产网手机版网站建设目标广东的seo产品推广服务公司
  • 日照网站建设哪家好seo研究协会
  • 怎么查网站是谁建的外贸高端网站设计公司
  • 做淘客需要用的网站培训
  • 网站链接跳转怎么做常用的网络推广方式有哪些
  • 网站主题下载小程序开发费用明细
  • 成都建设银行保安招聘网站长沙seo优化
  • 网站自适应手机端北京外包seo公司
  • 网站建设交流论坛地址十大教育培训机构排名
  • 自己做网站要不要钱搜索排名广告营销怎么做
  • 有什么做旅游攻略的网站好软文推广范文
  • 郑州营销型网站制作运营成都专业seo公司
  • 做网站客户需求seo整站优化哪家专业
  • 营销企业网站制作微信管理软件
  • 自贡建网站软文之家
  • 安徽建站优化哪里有北京企业网站seo平台
  • 东莞seo建站费用网络营销岗位有哪些
  • 有没有做维修的网站seo是如何做优化的
  • 代做论文网站今天的新闻发布会
  • 工作室网站设计全网推广
  • 河源市建设网站腾讯第三季度营收448亿元
  • 做web网站前端大学生创新创业大赛
  • 电子项目外包网站谷歌浏览器chrome官网