leetcode_c++:链表:Linked List Cycle II(142)
2016-07-18 13:38
579 查看
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
class Solution { public: ListNode *detectCycle(ListNode *head) { ListNode *slow = head; ListNode *fast = head; while(fast != NULL && fast->next != NULL){ slow = slow->next; fast = fast->next->next; if(slow == fast) break; } if(fast == NULL || fast->next == NULL) return NULL; slow = head; while(slow != fast){ slow = slow->next; fast = fast->next; } return fast; } };
相关文章推荐
- std::string用法总结
- leetcode_c++:链表:Linked List Cycle(141)
- C语言开发注意事项
- 素数环 搜索
- 23 DesignPatterns学习笔记:C++语言实现
- C++ —— 入门
- C++PP Chapter XVI String类和标准模板库
- effective c++读书笔记 条款3
- C++学习
- C++学习
- Base64Code.cpp
- 详细配置C++借助ADO连接Access数据库
- C++学习--派生&继承巧记
- C语言学习笔记(二)
- NYOJ 表达式求值问题
- ROS学习之 cpp消息发布者和消息订阅者
- UVA 1585-Score
- VC++6.0访问webservice
- vs中 .h和.cpp之间的切换
- C语言_初学结构体_plusC14.2