Linked List Cycle II(2014.2.7)
来源:互联网 发布:大学毕业证制作软件 编辑:程序博客网 时间:2024/06/10 12:02
/**
* 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* p=head;
ListNode* q=head;
while(q!=NULL&&q->next!=NULL){
p=p->next;
q=q->next->next;
if(p==q){
p=head;
while(p!=q){
p=p->next;
q=q->next;
}
return p;
}
}
return NULL;
}
};
0 0
- Linked List Cycle II(2014.2.7)
- 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
- 运行 DB2 的技巧
- 一级指针工程开发易发错误模型
- 设计类的网站网址
- Location-based Predictions for Personalized Contextual...(2013.10.29)
- 高效开发Android App的10个建议
- Linked List Cycle II(2014.2.7)
- JAVA泛型详解(一)
- 第7周作业2-极值计算
- ios代码重构
- 微信智能小机器人 小马 智能客服 调用
- Linked List Cycle(2014.2.7)
- android中使用ant打包APK
- LBSN 预测的想法(2013.11.11)
- 【spark系列3】spark开发简单指南