当前位置:网站首页>10、链表中倒数第k个节点
10、链表中倒数第k个节点
2022-07-28 09:58:00 【[email protected]】
- 给定一个链表: 1->2->3->4->5, 和 k = 2
返回链表 4->5
public ListNode getKthFromEnd(ListNode head, int k) {
ListNode cur = head, pre = head;
for(int i = 1; i <= k; i++){
cur = cur.next;
}
while(cur != null){
pre = pre.next;
cur = cur.next;
}
return pre;
}
- 利用双指针,真的很快
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124684474
边栏推荐
猜你喜欢

office2013以上输入数学公式

定了!就在7月30日!

房地产数字化转型方案:全方位数智化系统运营,助力房企管控实效提升

What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system

Flink - checkpoint Failure reason: Not all required tasks are currently running

工业品MRO采购网站有哪些优势?一文带你读懂
![[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals](/img/bf/0a968064a8f7c11b86a2a2820208e6.png)
[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals

It's settled! On July 30!
JWT login authentication + token automatic renewal scheme, well written!

Joint search set
随机推荐
7、二分法——寻找一组重复或者有序但是旋转的数组
Description of landingsite electronic label quppa firmware entering DFU status
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
银行入职考试要点汇总
Etcd(高可用KV数据库)
LinkedList source massage, ah comfortable
OSPF的LSA及优化
02.1.2.逻辑类型 bool
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
第四步-用户开发环境设置
It's settled! On July 30!
技术人 | 研发效能的思考总结
【学习笔记】border与period
uni-app进阶之生命周期
Function introduction and description of @jsontype annotation in fastjson
腾讯技术专家:解密亿级用户产品 微信、QQ、王者荣耀...全面上云实践!
B2B e-commerce website scheme for building materials industry: enable the transformation and upgrading of building materials enterprises to achieve cost reduction and efficiency improvement
为什么要考一级建造师,一建证书含金量有多高?
Illustrate three mainstream enterprise architecture models (recommended collection!)
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题