Linked List Cycle II
来源:互联网 发布:淘宝刷手兼职怎么做 编辑:程序博客网 时间:2024/05/21 11:31
原理在linked list cycle 中已经叙述过了 这里不再叙述
class Solution {public: ListNode *detectCycle(ListNode *head) { ListNode *fast=head; ListNode *slow=head; if(!head) return false; bool hascycle=false; while(slow&&fast&&fast->next) { slow=slow->next; fast=fast->next->next; if(slow==fast) { hascycle=true; break; } } if(!hascycle) return NULL; else { ListNode *temp=head; while(1) { if(temp==slow) break; temp=temp->next; slow=slow->next; } return slow; } }};
0 0
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Linked List Cycle II
- Android属性动画使用详解
- Linux:rm可不可以实现删除所有文件,除了demo文件
- win7 64 位下vs2008中OpenGL环境的配置
- Photoshop 手动画金标准流程
- asp.net几种控件类型的区别
- Linked List Cycle II
- java毕向东听课笔记19(字符串3)
- 避免Java应用中NullPointerException的技巧和最佳实践
- 【UNET自学日志】Part8 射击
- 为何各大网站启用HTTPS?运营商做了“好事”
- js跨域请求的问题
- svn常用命令
- iOS NSUserDefaults 简介,使用 NSUserDefaults 存储自定义对象
- 浏览器缓存机制和自己的一点疑问