当前位置:网站首页>10. The penultimate node in the linked list
10. The penultimate node in the linked list
2022-07-28 10:16:00 【[email protected]】
- Given a linked list : 1->2->3->4->5, and k = 2
Back to the list 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;
}
- With two pointers , It's really fast
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958224313.html
边栏推荐
- Performance test of API gateway APIs IX in Google cloud T2a and T2D
- 漏洞分析丨HEVD-0x8.IntegerOverflow[win7x86]
- leetcode——旋转数组的最小数字
- 海量数据TopN问题
- Continue to write the greatest work based on modelarts [play with Huawei cloud]
- leetcode076——数组中的第 k 大的数字
- What are the advantages of MRO purchasing website for industrial products? One article will help you understand
- 8、数组中出现次数超过一半的数字
- Arthas tutorial
- Step 4 - user development environment settings
猜你喜欢

Joint search set

利用正则表达式从文件路径中匹配文件名

【JS高级】js之函数、重载、匿名函数、作用域及作用域链_03

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

定了!就在7月30日!

Illustrate three mainstream enterprise architecture models (recommended collection!)

15、判断二维数组中是否存在目标值
![[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

Voice chat app - how to standardize the development process?

2022 uni app parsing token standard - use jsrsasign - climb the pit
随机推荐
pt-kill 查询中包含中文字符 导致工具失效的排查
Description of landingsite electronic label quppa firmware entering DFU status
Go json.Decoder Considered Harmful
Qt | 信号和槽的一些总结
(1)机器学习概念总结
Consul
Illustrate three mainstream enterprise architecture models (recommended collection!)
10分钟快速入门EVS【玩转华为云】
LIBCMTD.lib
12、双指针——合并两个有序链表
Kubernetes
Continue to write the greatest work based on modelarts [play with Huawei cloud]
2021-10-13arx
管道、管程、管态的区别
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
什么样的知识付费系统功能,更有利于平台与讲师发展?
用K-means聚类分类不同行业的关税模型
不登高山,不知天之高也;不临深溪,不知地之厚也
leetcode——旋转数组的最小数字
11、链表反转