Linked List Cycle II
来源:互联网 发布:qq飞车幻灵奇迹数据 编辑:程序博客网 时间:2024/06/16 06:09
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode detectCycle(ListNode head) { if (head == null){ return null; } ListNode slow = head; ListNode fast = head; int count = 0; while(true){ if (fast.next == null || fast.next.next == null){ return null; } count++; slow = slow.next; fast = fast.next.next; if (slow == fast){ break; } } slow = head; fast = head; for (int i=0;i<count;i++){ fast = fast.next; } while(true){ if (slow == fast){ return slow; } slow = slow.next; fast = fast.next; } }}
0 0
- 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
- Linked List Cycle II
- Call requires API level X (current min is X) 解决方法
- Linked List Cycle
- Android中SQLite应用详解
- servlet中获得路径
- 元查找树转双向链表
- Linked List Cycle II
- Learn Beautiful Soup(5) —— 使用BeautifulSoup改变网页内容
- please set a system env PAODING_DIC_HOME or Config paoding.dic.home in paoding-dic-home.properties p
- Clustering of residential areas based on residential conditions
- Java学习第一例:HelloWorld
- Uva10557XYZZY
- 康托展开及其逆运算
- 回收进程用户空间资源 exit()函数 _exit()函数 atexit()函数 on_exit()函数
- CMakeLists.txt与Makefile 的区别