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;
}
};