当前位置:网站首页>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;}}
边栏推荐
猜你喜欢
MySQL Basics
Pytorch GPU 训练环境搭建
NNLM、RNNLM等语言模型 实现 下一单词预测(next-word prediction)
pytorch框架实现老照片修复功能详细演示(GPU版)
Hinton2022年RobotBrains访谈记录
使用 ReportLab 绘制 PDF
Anaconda virtual environment migration
倒计时2天,“文化数字化战略新型基础设施暨文化艺术链生态建设发布会”启幕在即
从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
随机推荐
Li Mu hands-on learning deep learning V2-BERT fine-tuning and code implementation
wordpress建立数据库连接时出错
Detailed AST abstract syntax tree
染料修饰核酸RNA|[email protected] 610/[email protected] 594/Alexa 56
pytorch框架实现老照片修复功能详细演示(GPU版)
leetcode 16.01. 交换数字(不使用临时变量交换2个数的值)
边缘盒子+时序数据库,美的数字化平台 iBuilding 背后的技术选型
leetcode 剑指 Offer 15. 二进制中1的个数
盲埋孔PCB叠孔设计的利与弊
WPF .cs中使用资源文件中的ControlTemplate或Style并找到控件
从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
ESP8266-Arduino编程实例-WS2812驱动
2022.8.2
信使mRNA甲基化偶联3-甲基胞嘧啶(m3C)|mRNA-m3C
抖音web逆向教程
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
华为设备配置VRRP负载分担
「学习笔记」高斯消元
Auto.js脚本程序打包
Alexa染料标记RNA核糖核酸|RNA-Alexa 514|RNA-Alexa 488|RNA-Alexa 430