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

网站手机网站怎么建立seo快速排名关键词

网站手机网站怎么建立,seo快速排名关键词,花生壳动态域名申请,百度搜索引擎官网力扣#xff1a;LCR 022. 环形链表 II 给定一个链表#xff0c;返回链表开始入环的第一个节点。 从链表的头节点开始沿着 next 指针进入环的第一个节点为环的入口节点。如果链表无环#xff0c;则返回 null。 为了表示给定链表中的环#xff0c;我们使用整数 pos 来表示链…力扣LCR 022. 环形链表 II 给定一个链表返回链表开始入环的第一个节点。 从链表的头节点开始沿着 next 指针进入环的第一个节点为环的入口节点。如果链表无环则返回 null。 为了表示给定链表中的环我们使用整数 pos 来表示链表尾连接到链表中的位置索引从 0 开始。 如果 pos 是 -1则在该链表中没有环。注意pos 仅仅是用于标识环的情况并不会作为参数传递到函数中。 解法一 快慢指针检测到环后将慢重新指向头在将两个指针一步一步前进二者再次相遇处便是环的入口 原理为 #include iostream using namespace std;// 定义链表节点结构体 struct ListNode {int val;ListNode* next;ListNode(int x) : val(x), next(nullptr) {} };// 检测链表中是否有环并返回环的入口节点 ListNode* detectCycle(ListNode* head) {ListNode* slow head;ListNode* fast head;while (fast fast-next) {slow slow-next;fast fast-next-next;if (fast slow) {slow head;while (fast ! slow) {fast fast-next;slow slow-next;}return slow;}}return NULL; }// 用于创建带有环的链表的辅助函数 ListNode* createCycleListNode(int* values, int size, int cycleIndex) {if (values nullptr || size 0) {return nullptr;}ListNode* head new ListNode(values[0]);ListNode* tail head, *cycleNode nullptr;for (int i 0; i size; i) {ListNode* Node new ListNode(values[i]);tail-next Node;tail Node;if (i cycleIndex) {cycleNode Node;}}if (cycleNode) {tail-next cycleNode;}return head;}// 测试函数 void test(ListNode* head) {ListNode* cycleNode detectCycle(head);if (cycleNode) {std::cout Cycle detected at node with value: cycleNode-val std::endl;}else {std::cout No cycle detected. std::endl;} }// 主函数 int main() {// 示例创建一个链表其中包含环int values[] { 3, 2, 0, -4 };int cycleIndex 2; // 环的索引从0开始计数这里假设环连接在第三个节点后int size sizeof(values) / sizeof(values[0]);ListNode* head createCycleListNode(values, size, cycleIndex);test(head);// 清理链表delete head-next-next-next;delete head-next-next;delete head-next;delete head;return 0; }方法二哈希表 哈希表可以记录访问过的节点如果遇到环可以直接将入环的节点返回 #include iostream #include unordered_set using namespace std;// 定义链表节点结构体 struct ListNode {int val;ListNode* next;ListNode(int x) : val(x), next(nullptr) {} };// 检测链表中是否有环并返回环的入口节点ListNode* detectCycle(ListNode* head) {unordered_setListNode* seen;while (head ! nullptr) {if (seen.count(head)) {return head;}seen.insert(head);head head-next;}return nullptr; }// 用于创建带有环的链表的辅助函数 ListNode* createCycleListNode(int* values, int size, int cycleIndex) {if (values nullptr || size 0) {return nullptr;}ListNode* head new ListNode(values[0]);ListNode* tail head, * cycleNode nullptr;for (int i 0; i size; i) {ListNode* Node new ListNode(values[i]);tail-next Node;tail Node;if (i cycleIndex) {cycleNode Node;}}if (cycleNode) {tail-next cycleNode;}return head;}// 测试函数 void test(ListNode* head) {ListNode* cycleNode detectCycle(head);if (cycleNode) {std::cout Cycle detected at node with value: cycleNode-val std::endl;}else {std::cout No cycle detected. std::endl;} }// 主函数 int main() {// 示例创建一个链表其中包含环int values[] { 3, 2, 0, -4 };int cycleIndex 2; // 环的索引从0开始计数这里假设环连接在第三个节点后int size sizeof(values) / sizeof(values[0]);ListNode* head createCycleListNode(values, size, cycleIndex);test(head);// 清理链表delete head-next-next-next;delete head-next-next;delete head-next;delete head;return 0; }
http://www.pierceye.com/news/408492/

相关文章:

  • 西充县住房和城乡建设局网站深圳建设局网站打不开
  • 深圳常平网站建设制作公司网站开发qq群
  • 校园网站建设的感受论文专业微信网站建设公司首选
  • 国外免费logo设计网站免费网课平台
  • 高端网站设计定制公司页面跳转自动更新
  • 项目建设资金来源网站网站开发技术可以做什么工作
  • 可做易企秀的网站网页建站网站
  • 南京网站建设价格大型网站开发协调
  • 园林景观设计公司点评的网站和论坛大型网站搜索怎么做的
  • 河南省建设教育培训中心网站广告机器设备的价格表
  • 郑州做网站哪家最好中国能源建设集团有限公司是什么级别
  • 品牌设计公司排行榜前十名seo外包服务公司
  • 潍坊网站建设 58wordpress 酒店预订
  • 个人网站主机选择电商公司官网
  • 名城苏州网站龙岗网站建设价位
  • 免费手机网站制作学做网站游戏教程
  • 什么企业做网站广州市公司网站建设
  • 无锡万度网站建设推广电影链接赚佣金
  • 电子商务网站建设与管理实训网页设计与网站建设基础心得体会
  • 托管的服务器如何做网站花店网站模板 html
  • 南宁保洁网站建设在线 代理 输入网址
  • 微站是什么意思快站app下载
  • 网站让女友做网站模特做网站好一点的软件
  • 苏州h5网站建设wordpress 数据库配置
  • 环保网站模板下载农村电商平台怎么加入
  • 教育企业重庆网站建设建设公司网站征集信息的通知
  • 广州做网站找哪家好成都装饰设计公司排名
  • 做头发个人网站制作素材copyright wordpress
  • 高埗镇网站仿做企业网站建设市场分析
  • 网站怎么加icowordpress 程序员主题