You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's no condition regarding the lenght of the head
So, if the head is None or the length of the head is 1 (head.next is None), the rotated list is the same as the original list.
k can be 0 (the range of k is 0 <= k <= 2 * 10^9)
Calculate the effective number of rotations (k % length) to handle cases where k is greater than the length of the list
current=headlength=1whilecurrent.next:
current=current.nextlength+=1k%=lengthifnotk: # we don't have to lotate the linked listreturnheadcurrent.next=head# make a circular linked list
Traverse the list to find the new tail (the node that will become the new head after rotation) and the node just before it