Skip to content

Commit bde4810

Browse files
committed
solve linked list cycle
1 parent e131cf7 commit bde4810

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

linked-list-cycle/sora0319.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class sora0319 {
2+
public class Solution {
3+
public boolean hasCycle(ListNode head) {
4+
ListNode back = head;
5+
ListNode front = head;
6+
7+
while (front != null && front.next != null) {
8+
back = back.next;
9+
front = front.next.next;
10+
11+
if (back == front) {
12+
return true;
13+
}
14+
}
15+
16+
return false;
17+
}
18+
}
19+
}
20+

0 commit comments

Comments
 (0)