当前位置:网站首页>Reverse linked list drawing demonstration
Reverse linked list drawing demonstration
2022-07-24 00:23:00 【T.Y.Bao】
subject
Here's the head node of the list head , Please reverse the list , And return the inverted linked list .
/** * 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) {
}
}
Answer key
class Solution {
public ListNode reverseList(ListNode head) {
ListNode prev = null;
ListNode curr = head;
while (curr != null) {
ListNode next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}
}
author :LeetCode-Solution
link :https://leetcode.cn/problems/reverse-linked-list/solution/fan-zhuan-lian-biao-by-leetcode-solution-d1k2/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
Drawing demonstration

边栏推荐
猜你喜欢

【Android Kotlin】Property、Getter 和 Setter

PHP implements stripe subscription

win10下基于anaconda的detectron2安装

Nacos

Scheme for importing XMIND use cases into tapd (with code)

Codeforces Round #807 (Div. 2)(A-D)

Flutter | specifies the type of page return value

Pipeline pipeline project is built by declarative and jenkinsfile under Jenkins

English语法_指示代词 -such / the same

jenkins下使用声明式(Declarative)和Jenkinsfile的方式构建Pipeline流水线项目
随机推荐
Take stock of 10 new layer1 to prepare for the next bull market
GBase 8c系统表信息函数(二)
作为一个程序员,有什么想对新人说的吗?
Multi knapsack explanation of dynamic programming knapsack problem
蓝绿部署、金丝雀发布、A/B测试是什么
GBase 8c 位串操作符(一)
学习的快乐很多
MySQL之数据查询(SELECT)
【微信小程序】拍卖商品详情页设计与交互实现(包含倒计时、实时更新出价)
Scheme for importing XMIND use cases into tapd (with code)
Mysql database foundation
Flutter | the easiest way to add header and footer to listview
GBase 8c 模式可见性查询函数(一)
[Android kotlin] property, getter and setter
My meeting of OA project (query)
Mobile terminal H5 - a lifeline timeline
Blog expression Encyclopedia
GBase 8c访问权限查询函数(六)
合宙ESP32C3基于Arduino IDE框架下配置分区表
二叉搜索树的简易实现及剖析