class Solution {
public:
int kthToLast(ListNode* head, int k) {
ListNode* slow = head;
ListNode* fast = head;
for(int i = 0;i<k;i++)
{
fast = fast->next;
}
while(fast)
{
slow = slow->next;
fast = fast->next;
}
return slow->val;
}
};
leetcode每日一题第117天
最新推荐文章于 2024-07-08 23:32:11 发布