Linked List Cycle
来源:互联网 发布:经济数据公布时间表 编辑:程序博客网 时间:2024/06/06 17:16
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
定义两个指针,一个快,一个慢,快的追到慢的则存在环。
public Boolean hasCycle(ListNode head) {if (head == null) return false;ListNode fast, slow;fast = head.next;slow = head;while (fast != slow) {if(fast==null || fast.next==null)return false;fast = fast.next.next;slow = slow.next;} return true;}
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
- 两道笔试编程题(求水仙数和求平方根数组之和)
- 在myeclipse中写mysql语句出现的一个报错
- hdu5355 Cake
- HDOJ 1201 18岁生日
- hdu 2602 - Bone Collector(01背包)解题报告
- Linked List Cycle
- 粒子滤波(PF:Particle Filter)
- poj 2993 Emag eht htiw Em Pleh
- LeetCode之Same Tree
- 史上最全的CSS hack方式一览
- c++中的三种排序,比较基础,因为作为一个编程员总要会几种排序方法
- Apache OFbiz entity engine源码解读
- 字符串匹配的KMP算法
- excel的几个好用快捷键