141.Linked List Cycle (判断一个单链表是否有环)
2015-07-30 15:06
260 查看
public class Solution {
public boolean hasCycle(ListNode head) {
ListNode slow = head, fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
if (slow == fast)
return true;
}
return false;
}
}
public boolean hasCycle(ListNode head) {
ListNode slow = head, fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
if (slow == fast)
return true;
}
return false;
}
}
相关文章推荐
- NYOJ 68
- Android线程调度机制
- 通过wifi离线推广ios app
- 杭电1213 How Many Tables(并查集找根节点)
- SQL之CONVERT(varchar(100), GETDATE(), 0)
- MySQL的语句执行顺序
- fresh in werkzeug
- python eval的常见错误封装及利用原理
- Fibonacci的【兔子数列】 以及 【狐狸找兔子】的问题 及 算法!
- DHCP服务器 server 2003 到 server 2012 迁移 (二)
- python 安全编码&代码审计
- 如何让人的一生价值最大
- Android adb获取event
- Android MediaPlayer 和 NativePlayer 播放格式控制
- 64bit ubuntu 安装32bit的软件
- 24点问题(穷举法/C++)
- iOS开发UI篇—UIScrollView控件实现图片缩放功能
- iOS 与 Android 生命周期对比
- IOS OC声明变量在@interface括号中与使用@property的区别
- <input>禁止键盘及中文输入