Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def rotateRight(self, head: Optional[ListNode], k: int) -> Optional[ListNode]:
- if head==None or head.next==None or k==0:
- return head
- length=1
- current=head
- while current.next:
- current=current.next
- length+=1
- current.next=head
- k%=length
- rotate=length-k
- while rotate:
- current=current.next
- rotate-=1
- head=current.next
- current.next=None
- return head
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement