Reverse a singly linked list.

解题思路:

用Stack实现,JAVA实现如下:

    public ListNode reverseList(ListNode head) {
if(head==null)
return null;
Stack<ListNode> stack =new Stack<ListNode>();
ListNode temp=head;
while(temp!=null){
stack.push(temp);
temp=temp.next;
}
head=stack.pop();
temp=head;
while(!stack.isEmpty()){
temp.next=stack.pop();
temp=temp.next;
}
temp.next=null;
return head;
}

最新文章

  1. putpixel
  2. int *p()与int (*p)()的区别
  3. ajax普通弹窗;Bootstrp弹窗
  4. 洛谷P1519 穿越栅栏 Overfencing
  5. php5 date()获得的时间不是当前时间
  6. UNIX标准化及实现之限制
  7. 怎样在Ubuntu Scope中定义设置变量并读取
  8. TLD算法原理--学习理解之(二)
  9. SpringCloud-day08-Hystrix断路器
  10. Python学习day1 初识python&amp;环境安装
  11. N球M盒
  12. Pandas 基础(8) - 用 concat 组合 dataframe
  13. Spark:java.net.BindException: Address already in use: Service &#39;SparkUI&#39; failed after 16 retries!
  14. _itemmod_nopatch、_itemmod_nopatch_level、_itemmod_nopatch_spell、_itemmod_nopatch_src、_itemmod_nopatch_stat、_itemmod_nopatch_stat_prefix
  15. (转+整理)C#中动态执行代码
  16. C++ 11保留小数点的四舍五入方案
  17. codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)
  18. 二、django rest_framework源码之认证流程剖析
  19. python2-url编解码
  20. html表格设置

热门文章

  1. webapi支持跨域访问
  2. iSCSI配置流程
  3. poj.1988.Cube Stacking(并查集)
  4. 实现Android的不同精度的定位(基于网络和GPS)
  5. An error in projects
  6. HTTP及状态码汇总
  7. [codevs1029]遍历问题
  8. HDNOIP普及+提高整合
  9. Genymotion加速下载虚拟镜像速度慢失败Connection timeout
  10. 好无语的问题----include 后面需要空格么?