141. Linked List Cycle
2017-08-19 11:10
316 查看
/* Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 判断链表中是否有环 */ /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ bool hasCycle(struct ListNode *head){ if(!head) return 0; struct ListNode *fast=head,*slow=head; while(fast->next && fast->next->next) { fast=fast->next->next; slow=slow->next; if(fast==slow) //如果有环,快指针能够追上慢指针 return 1; } return 0; }
相关文章推荐
- leetcode 141:Linked List Cycle 问题与解答
- 141. Linked List Cycle
- LeetCode141:Linked List Cycle
- 【leetcode 141】 Linked List Cycle
- 141 linked list cycle
- Leetcode 141 Linked List Cycle
- leetcode 141 Linked List Cycle C++
- LeetCode 141: Linked List Cycle
- LeetCode 141 Linked List Cycle
- 【LeetCode】141 - Linked List Cycle
- [leetcode] #141 Linked List Cycle
- 【LeetCode】141 Linked List Cycle (java实现)
- 141 Linked List Cycle(判断链表是否有环Medium)
- LeetCode.142(141) Linked List Cycle && Linked List Cycle (II)
- 【leetcode】【141】Linked List Cycle
- OJ 141 --Linked List Cycle
- leetcode-Linked List Cycle-141
- 141. Linked List Cycle
- [LeetCode] 141-Linked List Cycle
- 141. Linked List Cycle