We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5c886ba commit 81c4ef6Copy full SHA for 81c4ef6
my-folder/problems/linked_list_cycle/solution.c
@@ -0,0 +1,27 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * struct ListNode {
4
+ * int val;
5
+ * struct ListNode *next;
6
+ * };
7
+ */
8
+#include <stdbool.h>
9
+
10
+bool hasCycle(struct ListNode *head) {
11
+ if (!head) { return false; };
12
+ struct ListNode* fast = head;
13
+ struct ListNode* slow = head;
14
15
+ while (true) {
16
+ fast = fast->next;
17
+ if (!fast) { return false; };
18
+ if (fast == slow) { return true; };
19
20
21
22
+ slow = slow->next;
23
+ }
24
25
26
27
+}
0 commit comments