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

工业品MRO采购网站有哪些优势?一文带你读懂

语音聊天app——如何规范开发流程?

【学习笔记】border与period

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
![[learning notes] border and period](/img/a4/5493f7eefc7dd0e38bc9a53a92b87b.png)
[learning notes] border and period

13 probability distributions that must be understood in deep learning

医药行业数字化建设,箭在弦上

MySQL架构原理

图解 3 种主流企业架构模式(建议收藏!)

TCP Basics
随机推荐
LSA and optimization of OSPF
2021.07.13 我们是这样崩的
02.1.2.逻辑类型 bool
CGAL编译错误
2022 uni app parsing token standard - use jsrsasign - climb the pit
Tencent technical experts: decrypt the 100 million user products wechat, QQ, King glory... Comprehensively practice on the cloud!
IE兼容性问题处理
It's settled! On July 30!
漏洞分析丨HEVD-0x8.IntegerOverflow[win7x86]
Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!
基于docker安装MySQL
Leetcode -- minimum number of rotation array
ASP.NET Core 6框架揭秘实例演示[29]:搭建文件服务器
API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
B2B2C系统亮点是什么?如何助力珠宝首饰企业打造全渠道多商户商城管理体系
arthas使用教程
Status Notice ¶
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
Redis design specification
Elk real time log analysis platform