Linked List Cycle
来源:互联网 发布:cnrds 数据产品 编辑:程序博客网 时间:2024/06/08 14:27
使用两个指针,一个faster一次走两步,一个slower一次走一步,若有环路则faster与slower必能相遇
class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; }}public class Solution { public boolean hasCycle(ListNode head) { ListNode faster = head; ListNode slower = head; while(faster != null && faster.next != null){ faster = faster.next.next; slower = slower.next; if(faster == slower) return true; } return false; }}
0 0
- leetcode Linked List Cycle & Linked List Cycle ||
- Linked List Cycle II Linked List Cycle
- 【LeetCode】Linked List Cycle
- Leetcode: Linked List Cycle
- Leetcode Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Linked List Cycle
- Linked List Cycle II
- Leetcode: Linked List Cycle
- LeetCode:Linked List Cycle
- Linked List Cycle II
- Linked List Cycle
- Linked List Cycle II
- [LeetCode]Linked List Cycle
- Linked List Cycle
- LeetCode | Linked List Cycle
- nyoj737 石子合并 详细
- 关于OGG的stats 进程名 reset命令
- android startActivityForResult()
- (转)解决VMWare中“二进制转换与此平台上的长模式不兼容,此虚拟环境中的长模式将被禁用”问题
- 用户浏览器操作行为的一种记录方法
- Linked List Cycle
- hdu 1043 八数码 单向广搜
- 关于JavaScript中使用appendChild和innerHTML动态添加一个元素的时间的比较
- missian(高性能异步RPC框架)-missian使用指南
- HTML5 新手入门指导
- 接收一个十六进制的数值字符串,输出该数值的十进制字符串。
- 水晶报表点滴
- 在阅读源代码或设计文档时,看到惊艳的技巧
- HBase学习笔记(二)———《安装教程》