赞
踩
目录
142. 环形链表 II - 力扣(LeetCode) (leetcode-cn.com)
题目描述:
- struct ListNode *detectCycle(struct ListNode *head) {
- struct ListNode * slow,*fast;
- slow = fast =head;
- //找meet节点
- while(slow && fast)
- {
- if(fast == NULL || fast->next==NULL)
- return NULL;
- slow = slow->next;
- fast = fast->next->next;
- if(slow == fast)
- {
- break;
- }
- }
- struct ListNode * meet = slow;
- //入环节点
- while(head&&meet)
- {
- if(head == meet)
- {
- return head;
- }
- meet = meet->next;
- head = head->next;
- }
- return NULL;
- }
由于本题思路较为复杂,我将其录制成了视频,视频链接:
C语言__Leetcode_142题环形链表II_哔哩哔哩_bilibili
大家可以二倍速观看哦~由于是第一次录制视频,希望大家多多包容哦--
(本篇完)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。