当前位置:网站首页>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
边栏推荐
猜你喜欢

语音聊天app——如何规范开发流程?

ES (8.1) certification topic

Voice chat app - how to standardize the development process?
![[openharmony] [rk2206] build openharmony compiler (2)](/img/0c/2e8290403d64ec43d192969f776724.png)
[openharmony] [rk2206] build openharmony compiler (2)

B2B2C系统亮点是什么?如何助力珠宝首饰企业打造全渠道多商户商城管理体系

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

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?

Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!

Illustrate three mainstream enterprise architecture models (recommended collection!)

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control
随机推荐
Arthas tutorial
数据库mysql基础
Etcd(高可用KV数据库)
网易笔试之不要二——欧式距离的典型应用
JWT 登录认证 + Token 自动续期方案,写得太好了!
SkiaSharp 之 WPF 自绘 拖曳小球(案例版)
Weekly report on July 27, 2022
Leetcode076 -- the kth largest number in the array
[openharmony] [rk2206] build openharmony compiler (2)
OSPF的LSA及优化
LinkedList source massage, ah comfortable
Sizebasedtriggingpolicy introduction
uni-app进阶之创建组件/原生渲染
【学习笔记】border与period
1. 两数之和
Flink - checkpoint Failure reason: Not all required tasks are currently running
【JZOF】14剪绳子
2022-uni-app解析token标准的方式-使用jsrsasign-爬坑过了
jvm原理
Introduction to timebasedrollingpolicy