当前位置:网站首页>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
边栏推荐
- 二维前缀和
- 深度学习必懂的 13 种概率分布
- Flink - checkpoint Failure reason: Not all required tasks are currently running
- 银行入职考试要点汇总
- 2022 uni app parsing token standard - use jsrsasign - climb the pit
- [esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
- office2013以上输入数学公式
- What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system
- OSPF的不规则区域,LSA和序列号
- Etcd (highly available kV database)
猜你喜欢

2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
![[esp32][esp idf] esp32s3 quickly build lvglv7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[esp32][esp idf] esp32s3 quickly build lvglv7.9
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology

Digital construction of pharmaceutical industry is on the verge

巧用ngx_lua做流量分组

6、双指针——递增数组两数之和与目标数相等

二分、三分、01分数规划【第III弹】

Arthas tutorial

Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached

二维前缀和
随机推荐
Talk about the problem of preventing others from debugging websites through console based on JS implementation
2021-10-13arx
二维前缀和
建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
Redis interview questions must be known and learned
PHP生成二维码(学习)
我用小程序容器让移动研发效率提升了5倍!
Uni app advanced creation component / native rendering
Performance test of API gateway APIs IX in Google cloud T2a and T2D
Massive data topn problem
QT | some summaries of signals and slots
博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
2021.07.13 我们是这样崩的
7、二分法——寻找一组重复或者有序但是旋转的数组
ES (8.1) certification topic
LSA and optimization of OSPF
Voice chat app - how to standardize the development process?
2022 uni app parsing token standard - use jsrsasign - climb the pit
Prometheus operation and maintenance tool promtool (IV) TSDB function