class Solution {
public:ListNode* rotateRight(ListNode* head, int k) {if (!head || k == 0) return head;int len = 1;ListNode* cur = head;while (cur->next) {len++;cur = cur->next;}cur->next = head; // 将链表首尾相连,形成循环链表int count = len - k % len;while (count--) {cur = cur->next;}ListNode* newHead = cur->next;cur->next = nullptr; // 断开循环链表return newHead;}
};