当前位置:网站首页>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
边栏推荐
- JWT login authentication + token automatic renewal scheme, well written!
- Xiao Hei stands up again and looks at leetcode:653. Sum of two IV - enter BST
- SuperMap iServer发布管理以及调用地图服务
- (十)defer关键字
- 深度学习必懂的 13 种概率分布
- 剑指offer
- Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
- 10 minute quick start EVs [play Huawei cloud]
- 13 probability distributions that must be understood in deep learning
- Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
猜你喜欢
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology

OSPF的拓展配置,选路原则,防环及重发布

软件设计师考前20问,注意啦!!

Redis面试题必知必会
![[esp32][esp idf] esp32s3 quickly build lvglv7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[esp32][esp idf] esp32s3 quickly build lvglv7.9

【JZOF】14剪绳子

技术人 | 研发效能的思考总结

Voice chat app - how to standardize the development process?

OSPF expansion configuration, routing principles, anti ring and re release

语音聊天app——如何规范开发流程?
随机推荐
JWT login authentication + token automatic renewal scheme, well written!
2022 uni app parsing token standard - use jsrsasign - climb the pit
软件设计师考前20问,注意啦!!
Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
12、双指针——合并两个有序链表
Being on duty less than 8 hours a day and being dismissed? Tencent's former employees recovered 13million overtime pay, etc., and the court won a compensation of 90000 in the final judgment
(10) Defer keyword
arthas使用教程
二分、三分、01分数规划【第III弹】
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
In retaliation for the dismissal of the company, I changed all code comments of the project!
【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03
深度学习必懂的 13 种概率分布
LSA and optimization of OSPF
Status Notice ¶
Redis设计规范
LandingSite电子标签Quuppa固件进入DFU状态说明
SQL Server、MySQL主从搭建,EF Core读写分离代码实现
基于docker安装MySQL