Skip to content

Commit c5ccd48

Browse files
toluwalase104adamant-pwn
authored andcommitted
Update tortoise_and_hare.md
I removed slow !=null from the while loop in hasCycle() because the fast pointer will always be ahead of the slow pointer, so it will reach the end of the linked list first (if it doesn't contain a cycle) In the case that, they both start at a null node, the fast pointer will be able to detect this by itself A minor change.
1 parent 2cb8312 commit c5ccd48

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/others/tortoise_and_hare.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public boolean hasCycle(ListNode head) {
4141
ListNode slow = head;
4242
ListNode fast = head;
4343

44-
while(slow !=null && fast != null && fast.next != null){
44+
while(fast != null && fast.next != null){
4545
slow = slow.next;
4646
fast = fast.next.next;
4747
if(slow==fast){

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy