当前位置:网站首页>JZ6 从尾到头打印链表
JZ6 从尾到头打印链表
2022-07-29 21:49:00 【syc596】
JZ6 从尾到头打印链表
从尾到头打印链表_牛客题霸_牛客网 (nowcoder.com)
// //递归
// import java.util.*;
// public class Solution {
// public void solve(ArrayList<Integer> list,ListNode head){
// if(head!=null){
// solve(list,head.next);
// list.add(head.val);
// }
// }
// public ArrayList<Integer> printListFromTailToHead(ListNode head) {
// ArrayList<Integer> list=new ArrayList<>();
// solve(list,head);
// return list;
// }
// }
//11
//栈
import java.util.*;
public class Solution {
public ArrayList<Integer> printListFromTailToHead(ListNode head) {
ArrayList<Integer> list=new ArrayList<>();
Stack<Integer> st=new Stack<>();
while(head!=null){
st.push(head.val);
head=head.next;
}
while(st.isEmpty()==false){
list.add(st.pop());
}
return list;
}
}
边栏推荐
猜你喜欢
GBASE 8s 数据库复合索引
OPEN数据 | 新库上线 | CnOpenDataA股上市公司社会责任报告数据
Add a logo to the upper left corner of the picture, add time and address to the lower left corner, and wrap the line when the address reaches the specified length
线性回归的多种实现方式
外文论文的格式规范要求有哪些?
【板栗糖GIS】arcmap—如何在表格空值处进行批量求和
高性能数据访问中间件 OBProxy(三):问题排查和服务运维
D. Rain(思维/线性代数/差分数组)
【板栗糖GIS】wps—如何查看表格中的超链接
四、HikariCP源码分析之初始化分析一
随机推荐
研究生怎么申请专利,流程是什么?
IDEA 快捷键
一篇关于Web3.0如何走向安全时代的说明
Add a logo to the upper left corner of the picture, add time and address to the lower left corner, and wrap the line when the address reaches the specified length
新手如何写专利?
怎样把某个公司所有的专利全部查到、一网打尽?
我想申请专利,却没有经验,如何学会写专利申请文件?
解决reudx中的异步问题 applyMiddleware thunk
5V升压充电8.4V芯片
撰写英文文献有哪些技巧?
笔记:fgets函数详解
力扣解法汇总593-有效的正方形
程序员「小镇做题」出身,月薪是父母半年收入 ……
针对自动识别大麦网滑块验证码,提出解决方案,并进行分析、总结
D. Rain(思维/线性代数/差分数组)
OPEN数据 | 新库上线 | CnOpenDataA股上市公司社会责任报告数据
新库上线 | CnOpenData国际货运代理信息数据
24小时伦敦金走势图分析
三、HikariCP源码分析之获取连接流程三
防火墙——SNAT和DNAT策略的原理及应用、防火墙规则的备份和还原