kucheasysa

Algoverse_adesh_38

Jul 7th, 2024
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def countNodesinLoop(head):
  2.     slow = fast = head
  3.     count=1
  4.     while fast and fast.next:
  5.         slow = slow.next
  6.         fast = fast.next.next
  7.         if slow == fast:
  8.             while slow.next!=fast:
  9.                 slow=slow.next
  10.                 count+=1
  11.             return count
  12.     else:
  13.         return 0
Advertisement
Add Comment
Please, Sign In to add comment