当前位置:网站首页>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!
- Introduction to thresholdfilter
- 广州地铁14号线新市墟站开建,白云区居民即将开启双线换乘模式!
- Consul
- Choosing a supplier service system is the first step for large health industry enterprises to move towards digital transformation
- uni-app进阶之生命周期
- Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
- 基于docker安装MySQL
- 技术人 | 研发效能的思考总结
- Irregular area of OSPF, LSA and serial number
猜你喜欢
![[jzof] 14 cut rope](/img/36/6f58b443a549ad245c1c4cfe5d13af.png)
[jzof] 14 cut rope

What are the highlights of B2B2C system? How to help jewelry enterprises build an omni channel multi merchant mall management system

B2B e-commerce website scheme for building materials industry: enable the transformation and upgrading of building materials enterprises to achieve cost reduction and efficiency improvement

ES (8.1) certification topic

Thinking and summary of technical personnel | R & D Efficiency

It's settled! On July 30!

PHP生成二维码(学习)

【学习笔记】border与period

Guangzhou metro line 14 xinshixu station is under construction, and residents in Baiyun District are about to start a double line transfer mode!

房地产数字化转型方案:全方位数智化系统运营,助力房企管控实效提升
随机推荐
️雄关漫道真如铁,而今迈步从头越️
ELK实时日志分析平台
建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
Xiao Hei stands up again and looks at leetcode:653. Sum of two IV - enter BST
银行入职考试要点汇总
Qt | 信号和槽的一些总结
Massive data topn problem
图解 3 种主流企业架构模式(建议收藏!)
博弈论 1.Introduction(组合游戏基本概念、对抗搜索、Bash游戏、Nim游戏)
PHP生成二维码(学习)
二分、三分、01分数规划 【第I弹】
LIBCMTD.lib
Joint search set
Irregular area of OSPF, LSA and serial number
剑指offer
Leetcode076 -- the kth largest number in the array
12、双指针——合并两个有序链表
arthas使用教程
巧用ngx_lua做流量分组
工业品MRO采购网站有哪些优势?一文带你读懂