Time: 254 ms (5.13%), Space: 8.1 MB (25.73%) - LeetHub

This commit is contained in:
Deven
2023-04-15 11:28:34 -04:00
parent 4974b3c1b8
commit 8250102ecf
@@ -0,0 +1,27 @@
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
bool hasCycle(struct ListNode *head) {
struct ListNode *current = head;
int index = 0;
while (current) {
struct ListNode *follow = head;
int follow_index = 0;
while (follow != current) {
follow = follow->next;
++follow_index;
}
if (follow_index < index) {
return true;
}
current = current->next;
++index;
}
return false;
}