当前位置:网站首页>3.用数组逆序打印链表
3.用数组逆序打印链表
2022-07-28 09:58:00 【[email protected]】
其实我最先想到的是用栈,因为栈是“先进后出”
class Solution {
public int[] reversePrint(ListNode head) {
LinkedList<Integer> stack = new LinkedList<Integer>();//定义栈
while(head != null){
stack.addLast(head.val);
head = head.next;
}
int[] array = new int[stack.size()];
for(int i = 0;i <array.length;i++){
array[i] = stack.removeLast();
}
return array;
}
}
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zjj1910066023/article/details/124575526
边栏推荐
猜你喜欢

In retaliation for the dismissal of the company, I changed all code comments of the project!

为报复公司解雇,我更改了项目的所有代码注释!

房地产数字化转型方案:全方位数智化系统运营,助力房企管控实效提升

关于软考高级要不要报班学习

OSPF的LSA及优化
JWT 登录认证 + Token 自动续期方案,写得太好了!

Digital transformation scheme of real estate: all-round digital intelligence system operation, helping real estate enterprises improve the effectiveness of management and control

OSPF expansion configuration, routing principles, anti ring and re release

API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
随机推荐
Edge team explains how to improve the comprehensive performance experience through disk cache compression technology
CloudCompare&PCL 匹配点采样一致性抑制
小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
[openharmony] [rk2206] build openharmony compiler (2)
It's settled! On July 30!
uni-app进阶之创建组件/原生渲染
16、字符串反转
ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
OSPF的LSA及优化
【JZOF】14剪绳子
02.1.2.逻辑类型 bool
语音聊天app——如何规范开发流程?
Digital construction of pharmaceutical industry is on the verge
Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
OSPF的拓展配置,选路原则,防环及重发布
Arthas tutorial
2021-10-13arx
安装gmp
Xiao Hei stands up again and looks at leetcode:653. Sum of two IV - enter BST