141. Linked List Cycle
2018-03-01 21:53
246 查看
Given a linked list, determine if it has a cycle in it.Follow up:
Can you solve it without using extra space?
bool hasCycle(struct ListNode *head) {
struct ListNode *fast=head, *slow=head;
while( slow && fast && fast->next ){
fast=fast->next->next;
slow=slow->next;
if(fast==slow) return true;
}
return false;
}
Can you solve it without using extra space?
bool hasCycle(struct ListNode *head) {
struct ListNode *fast=head, *slow=head;
while( slow && fast && fast->next ){
fast=fast->next->next;
slow=slow->next;
if(fast==slow) return true;
}
return false;
}
相关文章推荐
- [leetcode-141]Linked List Cycle(c)
- 141-Linked List Cycle
- leetcode: (141) Linked List Cycle
- Leetcode 141 Linked List Cycle
- 【LeetCode】141 Linked List Cycle (java实现)
- 141 Linked List Cycle
- LeetCode 141 Linked List Cycle(循环链表)(hash / set)
- Leetcode 141 Linked List Cycle
- Leetcode_141_Linked List Cycle
- 141. Linked List Cycle
- 141. Linked List Cycle
- LeetCode 141 Linked List Cycle
- LeetCode 141 -Linked List Cycle ( JAVA )
- Leetcode141——Linked List Cycle
- [LeetCode]: 141: Linked List Cycle
- 141. Linked List Cycle
- 141. Linked List Cycle
- 141. Linked List Cycle LeetCode
- leetcode-141-142 Linked List Cycle I II
- LeetCode(141)(142) Linked List Cycle I II