当前位置:网站首页>【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
2022-07-30 18:24:00 【@ have a cup of coffee】
算法汇总
以下是所有算法汇总,包括GitHub源码地址链接:力扣算法练习汇总(持续更新…)
题目
关键点
1、
2、
代码
1.解体方法
思路
代码
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */
class Solution {
public ListNode getKthFromEnd(ListNode head, int k) {
// 1. node size
int nodeCount = 0;
ListNode temp = head;
while (temp != null) {
nodeCount++;
temp = temp.next;
}
// 2. target node position
int position = nodeCount - k + 1;
temp = head;
nodeCount = 0;
while (temp != null) {
nodeCount++;
if (nodeCount == position) {
return temp;
}
temp = temp.next;
}
return null;
}
}
时间和空间复杂度
2.解题方法,如暴力法
思路
代码
时间和空间复杂度
边栏推荐
- 使用postman调接口报Content type ‘text/plain;charset=UTF-8‘ not supported
- 开源盛宴ApacheCon Asia 2022即将开幕,精彩不容错过!
- Application of time series database in the field of ship risk management
- "Ruffian Heng Embedded Bimonthly" Issue 59
- LayaBox---TypeScript---泛型
- 深化校企合作 搭建技术技能人才成长“立交桥”
- Kettle--MySQL生产数据库千万、亿级数据量迁移方案及性能优化
- 好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
- Kettle(二):连接SQL Server数据库
- 【开发者必看】【push kit】推送服务典型问题合集3
猜你喜欢
Vulkan与OpenGL对比——Vulkan的全新渲染架构
基础架构之Mongo
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
沃尔沃中国的年中总结,在“安全感”中寻找未来
OSPF详解(3)
DevEco Studio3.0下载失败,提示An unknown error occurred
AI基础:图解Transformer
【PHPWord】PHPOffice 套件之PHPWord快速入门
One year after graduation, I was engaged in software testing and won 11.5k. I didn't lose face to the post-98 generation...
cocos creater 热更重启导致崩溃
随机推荐
scrapy基本使用
原生js系列
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
Anaconda Navigator卡在loading applications
EMC VPLEX VS2 SPS电池更换详细探讨
LayaBox---TypeScript---变量声明
轻量级网络 ESPNetv2
AWS 控制台
分布式消息队列平滑迁移技术实战
Confluence OGNL注入漏洞复现(CVE-2022-26134)
"Ruffian Heng Embedded Bimonthly" Issue 59
LayaBox---TypeScript---函数
BI报表与数据开发
Hello, my new name is "Bronze Lock/Tongsuo"
SQL行列转换
固定资产可视化智能管理系统
基础架构之Redis
ByteArrayInputStream 类源码分析
One year after graduation, I was engaged in software testing and won 11.5k. I didn't lose face to the post-98 generation...
CMake库搜索函数居然不搜索LD_LIBRARY_PATH