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

node版本切换工具NVM以及npm源管理器nrm

622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)

单调栈及其应用

Detailed demonstration pytorch framework implementations old photo repair (GPU)

149. 直线上最多的点数-并查集做法

Hinton2022年RobotBrains访谈记录

头条服务端一面经典10道面试题解析

tRNA甲基化偶联3-甲基胞嘧啶(m3C)|tRNA-m3C (3-methylcy- tidine)

利用 rpush 和 blpop 实现 Redis 消息队列

从腾讯阿里等大厂出来创业搞 Web3、元宇宙的人在搞什么
随机推荐
Golang死信队列的使用
转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G
YARN功能介绍、交互流程及调度策略
abs()、fabs() 和 labs() 的区别
MySQL Basics
Mapper输出数据中文乱码
ARMuseum
RNA核糖核酸修饰Alexa 568/[email protected] 594/[email prote
php根据两点经纬度计算距离
Detailed demonstration pytorch framework implementations old photo repair (GPU)
glusterfs 搭建使用
LeetCode 899. 有序队列
一种能有效缓解环境噪声对音频质量干扰的方案
微导纳米IPO过会:年营收4.28亿 君联与高瓴是股东
Use ControlTemplate or Style from resource file in WPF .cs and find the control
ES6--剩余参数
glide set gif start stop
后台图库上传功能
alicloud3搭建wordpress
Detailed steps for tensorflow-gpu2.4.1 installation and configuration