从尾到头打印链表
2016-04-22 14:47
267 查看
public class ReverseLink { public class ListNode { int val; ListNode next = null; ListNode(int val) { this.val = val; } } public ArrayList<Integer> printListFromTailToHead(ListNode listNode) { ArrayList<Integer> list = new ArrayList<>(); Stack<Integer> stack = new Stack<>(); while (listNode != null) { stack.push(listNode.val); listNode = listNode.next; } while (!stack.isEmpty()) { list.add(stack.pop()); } return list; } }
相关文章推荐
- 安卓开发获取SDCard中某个目录下图片
- JAVA的输入输出基本操作样例
- c++宏定义命令
- Hadoop学习9--动态增加datanode
- 去除vim ^M符号
- 虚拟机的网络模式
- boost::spirit用法及EBNF表达式基础
- 浅谈撞库防御策略
- transform导致的border-radius失效问题
- linux定时任务crontab
- Android ViewAnimation 使用详解
- C++保存json文件(使用jsoncpp库)
- android基础知识-Vibrator(振动器) 使用
- 淘宝首页性能优化实践
- c#简答(1)
- 利用Memcache解决数据库高并发访问的瓶颈问题
- Java原生线程池原理
- HashMap,LinkedHashMap,TreeMap的区别
- MySQL wamp密码修改
- 例3-13设置ROI