Skip to content

Commit 8f71dd1

Browse files
committed
Solution for: LindedList has cyle
1 parent a83f158 commit 8f71dd1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/leetcode/LinkedListCycleHas.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package leetcode;
2+
3+
public class LinkedListCycleHas {
4+
public boolean hasCycle(ListNode head) {
5+
if(head==null || head.next==null) return false;
6+
ListNode slow= head;
7+
ListNode fast= head;
8+
while(fast!=null && fast.next!=null){
9+
fast= fast.next.next;
10+
slow= slow.next;
11+
if(fast==slow) return true;
12+
13+
}
14+
return false;
15+
}
16+
}

0 commit comments

Comments
 (0)