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

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

What are the advantages of MRO purchasing website for industrial products? One article will help you understand

C语言 二级指针详解及示例代码
![[esp32][esp idf] esp32s3 quickly build lvglv7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[esp32][esp idf] esp32s3 quickly build lvglv7.9

软件设计师考前20问,注意啦!!

14、双指针——盛最多水的容器

Performance test of API gateway APIs IX in Google cloud T2a and T2D

巧用ngx_lua做流量分组

21. 合并两个有序链表
![[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals](/img/bf/0a968064a8f7c11b86a2a2820208e6.png)
[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
随机推荐
Voice chat app - how to standardize the development process?
13 probability distributions that must be understood in deep learning
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
14、双指针——盛最多水的容器
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
Vulnerability analysis hevd-0x8.integeroverflow[win7x86]
On July 13, 2021, we collapsed like this
uni-app进阶之生命周期
简介
Cloudcompare & PCL matching point sampling consistency suppression
Consul
UEditor V1.4.3控制文件压缩
Summary of key points of bank entry examination
华为入股石墨烯材料厂商富烯科技,持股10%
CGAL编译错误
️雄关漫道真如铁,而今迈步从头越️
CloudCompare&PCL 匹配点采样一致性抑制
Status Notice ¶
【JZOF】14剪绳子
海量数据TopN问题