当前位置:网站首页>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;}}
边栏推荐
猜你喜欢
(十六)51单片机——红外遥控
Matlab paper illustration drawing template No. 42 - bubble matrix diagram (correlation coefficient matrix diagram)
ThreadLocal详解
Detailed demonstration pytorch framework implementations old photo repair (GPU)
MapReduce介绍及执行过程
小马智行起诉擎天智卡:索赔6000万 彭军称要斗争到底
汉源高科8光口12电口交换机千兆8光8电12电16电网管型工业以太网交换机
tRNA-m5C转运RNA(tRNA)修饰5-甲基胞嘧啶(m5C)|tRNA修饰m1Am2A (2-methyladenosine)
EMQX Newsletter 2022-07|EMQX 5.0 正式发布、EMQX Cloud 新增 2 个数据库集成
2022 年值得尝试的 7 个 MQTT 客户端工具
随机推荐
开源教育论坛| ChinaOSC
leetcode 剑指 Offer 58 - II. 左旋转字符串
双线性插值公式推导及Matlab实现
为什么 BI 软件都搞不定关联分析
php根据两点经纬度计算距离
【微信小程序2】事件传参与数据同步[03]
(十六)51单片机——红外遥控
ARMuseum
2022.8.2
ES6解构赋值--数组解构及对象解构
高性能计算软件与开源生态| ChinaOSC
pytorch框架实现老照片修复功能详细演示(GPU版)
Leetcode sword refers to Offer 15. 1 in the binary number
Edge box + time series database, technology selection behind Midea's digital platform iBuilding
622 设计循环队列——Leetcode天天刷【循环队列,数组模拟,双指针】(2022.8.2)
转运RNA(tRNA)甲基化修饰7-甲基胞嘧啶(m7C)|tRNA-m7G
C51 存储类型与存储模式
【飞控开发高级教程6】疯壳·开源编队无人机-AI语音控制
基础软件与开发语言开源论坛| ChinaOSC
JMeter笔记5 |Badboy使用和录制