当前位置:网站首页>Print linked list from end to beginning
Print linked list from end to beginning
2022-07-30 00:15:00 【Ryuzaki Liuhe】
Title:
Enter the head node of a linked list, and return the value of each node from the end to the beginning (returned as an array)
Example 1:
Input: head= [1,3,2]
Output: [2,3,1]
Analysis:
Thinking about creating an array first, you need to determine how many numbers there are,After confirming, it can be loaded directly.
Code:
public class ReversePrint {public int[] reversePrint(ListNodehead) {if (head == null){return new int[0];}ListNode temp = head;int count = 0;//Calculate the length of the returned arraywhile (temp != null){count++;temp = temp.next;}int k = count - 1;int[] res = new int[count];//You can start assigning valueswhile (head !=null){res[k--] = head.val;head = head.next;}return res;}}
边栏推荐
- YOLO数据格式说明与转换
- 4 hotspot inquiry networks necessary for new media operations
- I.MX6U-驱动开发-3-新字符驱动
- 【集训DAY18】Welcome J and Z 【动态规划】
- 绘制几何图形
- 关于 byte 的范围
- 工厂模式
- Types and check set (set), study T treasure code
- Douyin short video traffic acquisition strategy, mastering these will definitely be a hit
- 【集训DAY16】KC‘s Can 【动态规划】
猜你喜欢

Towhee 每周模型

UE4 制作十字准心+后坐力

WeChat developer tools set the tab size to 2

Worthington Dissociation Enzymes: Collagenase and Four Basic Profiles

Worthington Optimized Technology: Cell Quantification

经典论文-SqueezeNet论文及实践

7.27
Comprehensive Practice - Three-Mison Chess Mini Game

He cell separation technology 丨 basic primary cell separation methods and materials

中文语义匹配
随机推荐
工厂模式
vmtouch——Linux下的文件缓存管理神器
EA & UML Sun Gong Yip - Multitasking Programming Super Introductory - (7) About mutex, you must know
重建二叉树
窗口函数笔记
Low dropout linear regulator MPQ2013A-AEC1 brand MPS domestic replacement
1592. 重新排列单词间的空格
Worthington Dissociation Enzymes: Trypsin and Frequently Asked Questions
opencv基本图像的滤波
抖音短视频流量获取攻略,掌握好这些一定可以出爆款
4 hotspot inquiry networks necessary for new media operations
新闻文本分类
Worthington Dissociation Enzymes: Collagenase and Four Basic Profiles
Worthington优化技术:细胞定量
ZLMediaKit源码分析 - WebRtc连接迁移
【集训DAY16】ALFA【凸壳】【计算几何】
YOLO数据格式说明与转换
Decision tree principle and code implementation
Replace the executable file glibc version of the one
Mysql internal and external connections