class Solution(object): def rotateRight(self, head, k): """ :type head: ListNode :type k: int :rtype: ListNode """ if not head: return if head.next==None: return head if k==0: return head q=head m=0 while q: m+=1 q=q.next n=k%m while n: q=head p=q.next while p.next!=None: q,p=q.next,p.next p.next=head q.next=None head=p n-=1 return head
执行用时 :44 ms, 在所有 python 提交中击败了14.88%的用户
内存消耗 :11.8 MB, 在所有 python 提交中击败了26.96%的用户
——2019.10.25