We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
What is wrong with the below code -> It works in leedcode but fails here
if head is None:
return False
#if head and head.next is None:
# return False
slow = head
fast = head.next
while slow:
if slow == fast:
return True
if fast and fast.next:
fast = fast.next.next
else:
return False
slow = slow.next
return False
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
What is wrong with the below code -> It works in leedcode but fails here if head is None: return False #if head and head.next is None: # return False slow = head fast = head.next while slow: if slow == fast: return True if fast and fast.next: fast = fast.next.next else: return False slow = slow.next return False