Skip to content

Commit 8080f6d

Browse files
committed
Created 141-Linked-List-Cycle.cs
1 parent b23c604 commit 8080f6d

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

csharp/141-Linked-List-Cycle.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)