LeetCode:Linked List Cycle II
2015-08-31 12:02
465 查看
Given a linked list, return the node where the cycle begins. If there is no cycle, return
Note: Do not modify the linked list.
Follow up:
Can you solve it without using extra space?
null.
Note: Do not modify the linked list.
Follow up:
Can you solve it without using extra space?
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *detectCycle(ListNode *head) { ListNode *slow = head,*fast=head; while(fast&&fast->next) { slow=slow->next; fast=fast->next->next; if(slow==fast) { ListNode *slow2=head; while(slow2!=slow) { slow2=slow2->next; slow=slow->next; } return slow2; } } return NULL; } };
相关文章推荐
- jQuery实现鼠标滑过点击事件音效试听
- js实现仿百度风云榜可重复多次调用的TAB切换选项卡效果
- 栈的应用:后缀表达式到中缀表达式的转换
- Oracle_如何从数据库 11.2 降级至之前的版本(包括 11.2.0.3-11.2.0.1)
- C++ 各种全局常量的声明方式的优缺点?
- WPF comboBox内字体选择器的简单使用
- CocoaAsyncSocket 文档3:介绍GCDAsyncSocket
- 仿QQ消息提示小圆点---启发demo
- windows系统卸载程序不彻底,系统服务中有残留如何删除
- 矢量图网站
- Coursera-C程序设计进阶-编程题#1:单词翻转
- 梯度检验!
- 一道让人蛋疼的面试题
- Android Camera open流程
- 8 - String to Integer (atoi)
- hibernate一对多关联映射—单向
- MySQL出现Errcode:28错误提示解决办法
- iOS开发- UICollectionView详解+实例
- MFC画图
- IOS之分析网易新闻存储数据(CoreData的使用,增删改查)