142. Linked List Cycle II
来源:互联网 发布:网络大电影方案 编辑:程序博客网 时间:2024/06/05 05:51
/** * 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) { if(head == NULL) return NULL; ListNode* slow = head; ListNode* fast = head; fast = fast->next; while(slow != fast) { if(fast == NULL || fast->next == NULL || fast->next->next == NULL) return NULL; slow = slow->next; fast = fast->next->next; } slow = slow->next; ListNode* p = head; while(p != slow) { p = p->next; slow = slow->next; } return slow; }};
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
- 【BATCH程序】显示隐藏的文件
- windows10 在文件夹里面邮件一下打开当前路径的命令行
- nefu 18 滑雪
- PE 318【二项式定理】
- Hadoop源码解析之申请与分配Container
- 142. Linked List Cycle II
- 梅森旋转算法--伪随机数(加密、身份信息ID号)
- 设计表时给哪些字段加索引,索引的用处,以及能不能给所有字段加索引
- Android OTA相关博文
- pentaho CDA缓存配置
- Linux内核PROC文件系统的初始化和主要函数分析
- POJ 3281 (网络流)
- html 字体围绕图片效果
- 将HH:mm:ss格式的时间转换成分钟数