//翻转倒数第k个结点
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
int n = 0;
for (auto p = pListHead; p; p = p->next) n ++ ;
if (n < k) return nullptr;
auto p = pListHead;
for (int i = 0; i < n - k; i ++ ) p = p->next;
return p;
}
};
/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};*/
class Solution {
public:
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
int n = 0;
for (auto p = pListHead; p; p = p->next) n ++ ;
if (n < k) return nullptr;
auto p = pListHead;
for (int i = 0; i < n - k; i ++ ) p = p->next;
return p;
}
};
2020-05-07
在牛客打卡15天,今天学习:刷题 1 道/代码提交 1 次
全部评论
相关推荐
点赞 评论 收藏
分享
01-20 11:00
广东实验中学 算法工程师 点赞 评论 收藏
分享
飞花断音:gpt4o加粗有点搞笑,cn域名备案批准你使用国外的大模型吗?
点赞 评论 收藏
分享