【力扣 009】141. 环形链表
141. 环形链表
解法1:
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution 10 { 11 public: 12 bool hasCycle(ListNode *head) 13 { 14 ListNode * fast, *slow; 15 fast = slow = head; 16 while(fast && fast->next) 17 { 18 slow = slow->next; 19 fast = fast->next->next; 20 if(fast == slow) 21 return true; 22 } 23 return false; 24 } 25 };