剑指offer14: 链表中倒数第K个结点
class Solution {
public:
unsigned int cnt=0;
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if(pListHead==NULL)
return NULL;
ListNode* node=FindKthToTail(pListHead->next,k);
if(node!=NULL)
return node;
cnt++;
if(cnt==k)
return pListHead;
else
return NULL;
}
};
class Solution {
public:
unsigned int cnt=0;
ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) {
if(pListHead==NULL)
return NULL;
ListNode* node=FindKthToTail(pListHead->next,k);
if(node!=NULL)
return node;
cnt++;
if(cnt==k)
return pListHead;
else
return NULL;
}
};
2020-05-11
在牛客打卡32天,今天学习:刷题 3 道/代码提交 3 次
全部评论
相关推荐
点赞 评论 收藏
分享
01-12 20:31
东北大学 Java
冰炸橙汁_不做oj版:虽然石凯说这大作业能用但是我感觉走java后端还是算了吧,项目一般放两个就行,建议到知识星球上找个项目把前两个换掉 点赞 评论 收藏
分享
点赞 评论 收藏
分享