class Solution { public: ListNode* rotateLinkedList(ListNode* head, int k) { if(!head) return head; ListNode *p = head; int len = 1; while(p->next) { p = p->next; len++; } if(k==len) return head; k = k%len; p = head; for(int i = 0;i<len-k-1;i++) { p = p->next; } ListNode*t = p->next; while(t->next) t= t->next; t->next = head; head = p->next; p->next = nullptr; return head; } };