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 b23c604 commit 8080f6dCopy full SHA for 8080f6d
csharp/141-Linked-List-Cycle.cs
@@ -0,0 +1,25 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * public class ListNode {
4
+ * public int val;
5
+ * public ListNode next;
6
+ * public ListNode(int x) {
7
+ * val = x;
8
+ * next = null;
9
+ * }
10
11
+ */
12
+
13
+public class Solution {
14
+ public bool HasCycle(ListNode head) {
15
+ ListNode slow = head, fast = head;
16
17
+ while (fast != null && fast.next != null)
18
+ {
19
+ fast = fast.next.next;
20
+ slow = slow.next;
21
+ if (slow.Equals(fast)) return true;
22
+ }
23
+ return false;
24
25
+}
0 commit comments