当前位置:网站首页>Power button 206 - reverse list - the list
Power button 206 - reverse list - the list
2022-08-03 20:12:00 【Zhang Ran Ran √】
Title description
Give you the head node of the singly linked list head, please reverse the linked list and return the reversed linked list.
Solution ideas
This is a simple question about linked lists, examining the inversion of linked lists;
We consider changing the point of the pointer, no need to create a new linked list;
Leverage a picture from Karge:

Input and output example


Code
/*** Definition for singly-linked list.* public class ListNode {* int val;*ListNode next;* ListNode() {}* ListNode(int val) { this.val = val; }* ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/class Solution {public ListNode reverseList(ListNode head) {ListNode pre = null;ListNode tem = null;ListNode cur = head;while(cur != null){tem = cur.next;cur.next = pre;pre = cur;cur = item;}return pre;}}边栏推荐
- Li Mu hands-on learning deep learning V2-BERT fine-tuning and code implementation
- 若依集成browscap读取浏览器用户代理
- 若依集成easyexcel实现excel表格增强
- 安装anaconda并创建虚拟环境
- 开源生态研究与实践| ChinaOSC
- leetcode 072. 求平方根
- wordpress建立数据库连接时出错
- 化算力为战力:宁夏中卫的数字化转型启示录
- 【leetcode】剑指 Offer II 007. 数组中和为 0 的三个数(双指针)
- 622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
猜你喜欢
随机推荐
Anaconda virtual environment migration
不知道这4种缓存模式,敢说懂缓存吗?
演讲议题及嘉宾重磅揭晓,TDengine 开发者大会推动数据技术“破局”
Kubernetes资源编排系列之三: Kustomize篇 作者 艄公(杨京华) 雪尧(郭耀星)
EasyCVR平台海康摄像头语音对讲功能配置的3个注意事项
Statistical machine learning 】 【 linear regression model
leetcode 16. 数值的整数次方(快速幂+递归/迭代)
leetcode 1837. K 进制表示下的各位数字总和
化算力为战力:宁夏中卫的数字化转型启示录
Auto.js脚本程序打包
第三方验收测试报告有什么作用?如何获取权威软件测试报告?
ES6--剩余参数
调用EasyCVR接口时视频流请求出现404,并报错SSL Error,是什么原因?
高位套牢机构,用友网络的信任危机是如何产生的?
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
glide set gif start stop
Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
leetcode 125. 验证回文串
Li Mu hands-on learning deep learning V2-BERT fine-tuning and code implementation









