142. Linked List Cycle II(unsolved)
来源:互联网 发布:mac 应用程序的路径 编辑:程序博客网 时间:2024/05/17 22:30
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
Note: Do not modify the linked list.
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution { ListNode *detectCycle(ListNode *head) { if (head == NULL || head->next == NULL) return NULL; ListNode *slow = head; ListNode *fast = head; ListNode *entry = head; while (fast->next && fast->next->next) { slow = slow->next; fast = fast->next->next; if (slow == fast) { // there is a cycle while(slow != entry) { // found the entry location slow = slow->next; entry = entry->next; } return entry; } } return NULL; // there has no cycle}};
0 0
- 142. Linked List Cycle II(unsolved)
- 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
- swift中的assert
- Java 多线程同步的五种方法
- delphi CopyFile的基础用法
- kubernetes+docker 手动安装
- hdu 1540 Tunnel Warfare 线段树 单点更新,查询区间长度,区间合并
- 142. Linked List Cycle II(unsolved)
- 数据结构- 串的模式匹配算法:BF和 KMP算法
- DES、RSA、MD5、SHA、随机生成加密与解密
- jQuery easyUI datagrid的一些使用
- Java kryo/protobuf/protostuff序列化 or Json 性能对比
- 种类判断
- jvm调优笔记(二)—— GC策略&内存申请、对象衰老
- Java数据结构和算法(一)——开篇
- c/汇编的混合编程