leetcode-141. 环形链表
本文最后更新于:2022年8月1日 晚上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public: bool hasCycle(ListNode *head) {
ListNode* fast = head; ListNode* slow = head;
while (fast != NULL && fast->next != NULL) { fast = fast->next->next; slow = slow->next;
if (fast == slow) return true; } return false; } };
|