全部评论
public class Solution { ArrayList<Integer> resultArray = new ArrayList<>(); public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { Stack<Integer> s = new Stack<Integer>(); ListNode p = listNode; while(p != null) { s.push(p.val); p = p.next; } while (!s.empty()) { resultArray.add(s.pop()); //利用栈的特性 } return resultArray; } }
点赞 回复 分享
发布于 2021-04-14 16:26
public class Solution { ArrayList<Integer> arrayList = new ArrayList<Integer>(); public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { if(listNode!=null){ this.printListFromTailToHead(listNode.next); //递归的目的是让add倒序执行 arrayList.add(listNode.val); } return arrayList; } }
点赞 回复 分享
发布于 2021-04-14 16:20

相关推荐

不愿透露姓名的神秘牛友
2025-11-19 14:56
点赞 评论 收藏
分享
2025-11-17 14:18
门头沟学院 C++
代码飞升_不回私信人...:这种感觉还好。只是你写一个PPT,可能他面的快一点而已。那种让你写什么方案,写什么代码的那种。就没必要去了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务