当前位置:网站首页>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;}}边栏推荐
猜你喜欢
随机推荐
Detailed AST abstract syntax tree
wordpress建立数据库连接时出错
若依集成easyexcel实现excel表格增强
宁德时代2号人物黄世霖辞任副董事长:身价1370亿
自定义form表单验证
李沐动手学深度学习V2-BERT微调和代码实现
详解AST抽象语法树
Detailed demonstration pytorch framework implementations old photo repair (GPU)
面试官:为什么 0.1 + 0.2 == 0.300000004?
嵌入式分享合集27
Li Mu hands-on learning deep learning V2-BERT fine-tuning and code implementation
软件测试基本流程有哪些?权威的第三方软件检测机构推荐
2022 CCF中国开源大会会议通知(第三轮)
PHP according to the longitude and latitude calculated distance two points
Auto.js实现朋友圈自动点赞
【微信小程序2】事件传参与数据同步[03]
8.3模拟赛总结
调用EasyCVR云台控制接口时,因网络延迟导致云台操作异常该如何解决?
基础软件与开发语言开源论坛| ChinaOSC
【飞控开发高级教程6】疯壳·开源编队无人机-AI语音控制








