leetcode 141. linked list cycle



  1. Linked List Cycle:题目链接
    官方解析:题目链接

AC code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
bool (struct ListNode *head) {
if (head == NULL || head->next == NULL) {
return false;
}
struct ListNode * fast = head->next, * slow = head;
while (slow != fast) {
if (fast == NULL || fast->next == NULL) {
return false;
}
slow = slow->next;
fast = fast->next->next;
}
return true;
}