[LeetCode] Linked List Cycle
2014-11-23 21:05
363 查看
Given a linked list, determine if it has a cycle in it.
class Solution { public: bool hasCycle(ListNode *head) { ListNode *p = head; ListNode *q = head; while(q && q -> next){ p = p -> next; q = q -> next -> next; if(p == q) return true; } return false; } };
相关文章推荐
- [LeetCode]LinkedList Cycle
- leetcode — linked-list-cycle
- [leetcode]Linked List Cycle II @ Python
- leetcode---linked-list-cycle-ii---链表
- Leetcode: Linked List Cycle
- LeetCode:Linked List Cycle
- Linked List Cycle II--LeetCode
- [LeetCode] Linked List Cycle II Solution
- 《leetCode》:Linked List Cycle II
- 【LeetCode笔记】Linked List Cycle
- leetcode 11 Linked List Cycle
- LeetCode:Linked List Cycle
- LeetCode------Linked List Cycle
- leetcode 137: Linked List Cycle
- [题解][LeetCode][Linked List Cycle]
- leetcode142~Linked List Cycle II
- [leetcode]Linked List Cycle
- leetCode #142 Linked List Cycle II
- [leetcode]Linked List Cycle II
- leetcode linked list cycle