142. Linked List Cycle II
来源:互联网 发布:网络营销策划案 汽车 编辑:程序博客网 时间:2024/04/28 08:05
class Solution {public: ListNode *hasCycle(ListNode *head) { if(!head || !head->next) return NULL; ListNode *p1 = head, *p2 = head; while(p1 && p2){ p1 = p1->next; if(p2->next == NULL) return NULL; p2 = p2->next->next; if(p1 == p2) return p1; } return NULL; } ListNode *detectCycle(ListNode *head) { ListNode *p = hasCycle(head); if(!p) return NULL; ListNode *s = head; while(s != p){ s = s->next; p = p->next; } return s; }};
阅读全文
0 0
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- 142. Linked List Cycle II
- python一些关于pwn的应用
- 11g Linux RAC 安装文档
- 怎么进行面向对象设计(一)
- 母函数模板
- 地铁模型
- 142. Linked List Cycle II
- 我的数模之旅(一)
- 虚拟内存
- Linux shell字符串截取与拼接
- Zenject
- 要求通过java读取文本并把文本中的每一行后面的三个成绩相加, 最后按从大到小的顺序输出到另一个文本文件中.
- 相似度和相异度、常用距离度量、余弦相似度
- TX2(2)--Jetson TX2 Caffe安装与文件配置
- dba,user,v$等开头的常用表和视图