AC code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14bool hasCycle(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;
}
leetcode 141. Linked List Cycle
本文标题:leetcode 141. Linked List Cycle
文章作者:XerDemo
发布时间:2019-07-21, 15:52:17
最后更新:2019-07-21, 16:04:16
原始链接:https://xerdemo.github.io/2019/07/21/leetcode-141-Linked-List-Cycle/
许可协议: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。