# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def rotateRight(self, head: ListNode, k: int) -> ListNode:
l=0
p=head
while p:
p=p.next
l+=1
if (l==0): return None
n=l-k%l
p=head
i=1
while i<n:
p=p.next
i+=1
if p.next==None:return head
newhead=p.next
p.next=None
p=newhead
while p.next:
p=p.next
p.next=head
return newhead
7891

被折叠的 条评论
为什么被折叠?



