当前位置:网站首页>3. Print the linked list in reverse order with the array
3. Print the linked list in reverse order with the array
2022-07-28 10:16:00 【[email protected]】
In fact, the first thing I thought of was using stacks , Because the stack is “ First in, then out ”
class Solution {
public int[] reversePrint(ListNode head) {
LinkedList<Integer> stack = new LinkedList<Integer>();// Define stack
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://yzsam.com/2022/209/202207280958224800.html
边栏推荐
猜你喜欢

On July 13, 2021, we collapsed like this

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?

2022 uni app parsing token standard - use jsrsasign - climb the pit

我用小程序容器让移动研发效率提升了5倍!

巧用ngx_lua做流量分组

15、判断二维数组中是否存在目标值

C语言 二级指针详解及示例代码
![[openharmony] [rk2206] build openharmony compiler (2)](/img/0c/2e8290403d64ec43d192969f776724.png)
[openharmony] [rk2206] build openharmony compiler (2)

剑指offer

ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
随机推荐
Thinking and summary of technical personnel | R & D Efficiency
15、判断二维数组中是否存在目标值
10、链表中倒数第k个节点
配置树莓派,过程和遇到问题
Voice chat app - how to standardize the development process?
7、二分法——寻找一组重复或者有序但是旋转的数组
定了!就在7月30日!
管道、管程、管态的区别
Leetcode -- minimum number of rotation array
9、删除链表中节点
Tencent technical experts: decrypt the 100 million user products wechat, QQ, King glory... Comprehensively practice on the cloud!
SuperMap iServer发布管理以及调用地图服务
【云驻共创】企业数字化转型,华为云咨询与你同行
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
Lucene 查询语法备忘
[openharmony] [rk2206] build openharmony compiler (2)
jvm原理
初识SuperMap iDesktop
数据库mysql基础
按位与、或、异或等运算方法