LCR 140. 训练计划 II - 力扣(LeetCode)

快慢指针。快指针臂慢指针快cnt个元素到最后;
class Solution {
public:
ListNode* trainingPlan(ListNode* head, int cnt) {
struct ListNode* quick = head;
struct ListNode* slow = head;
for(int i = 0; i < cnt ; i++)
{
quick = quick->next;
}
while(quick)
{
quick = quick->next;
slow = slow->next;
}
return slow;
}
};






![[Cloud Networking] Layer 2](https://img-blog.csdnimg.cn/img_convert/ae778f4d1be9c7891bdf05ac5f63e640.webp?x-oss-process=image/format,png)












