题目:
题解:
class Solution:def rotateRight(self, head: ListNode, k: int) -> ListNode:if k == 0 or not head or not head.next:return headn = 1cur = headwhile cur.next:cur = cur.nextn += 1if (add := n - k % n) == n:return headcur.next = headwhile add:cur = cur.nextadd -= 1ret = cur.nextcur.next = Nonereturn ret