Skip to content

Commit b9dbb14

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

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/leetcode/LinkedListCycleHas.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
public class LinkedListCycleHas {
44
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;
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;
1515
}
1616
}

0 commit comments

Comments
 (0)