Advertisement
kucheasysa

Algoverse_adesh_46

Jul 15th, 2024
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. class Solution:
  2.     def rotateRight(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:
  3.         if head==None or head.next==None or k==0:
  4.             return head
  5.         length=1
  6.         current=head
  7.         while current.next:
  8.             current=current.next
  9.             length+=1
  10.         current.next=head
  11.         k%=length
  12.         rotate=length-k
  13.         while rotate:
  14.             current=current.next
  15.             rotate-=1
  16.         head=current.next
  17.         current.next=None
  18.         return head
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement