[Microsoft] Linked List Cycle
来源:互联网 发布:蓝牙怎么传软件 编辑:程序博客网 时间:2024/06/06 08:52
/** * Definition for ListNode. * public class ListNode { * int val; * ListNode next; * ListNode(int val) { * this.val = val; * this.next = null; * } * } */ public class Solution { /** * @param head: The first node of linked list. * @return: True if it has a cycle, or false */ public boolean hasCycle(ListNode head) { if(head==null){ return false; } ListNode fast=head; ListNode slow=head; while(fast.next!=null && fast.next.next!=null){ //只有保证fast.next不为空,才能有fast.next.next slow=slow.next; fast=fast.next.next; if(slow==fast){ //最终slow追上fast return true; } } return false; } }
阅读全文
0 0
- [Microsoft] Linked List Cycle
- 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
- 《Android那些事》——ListView中Button点击事件解决方案
- Echarts与后台java交互 数据动态变化
- 如何拆掉受害这堵墙
- 解决RecyclerView复用导致EdittText、CheckBox等显示异常的问题
- BZOJ 3065: 带插入区间K小值
- [Microsoft] Linked List Cycle
- 单例设计模式
- 628. Maximum Product of Three Numbers
- 同余的基本定理
- 深度学习库的安装
- Linux 目录及文件基础命令操作
- MyEclipse无法导出WAR包
- (63)ListIterator用法、List均有的增删改查
- leetcode 70. Climbing Stairs