反转链表 leetcode206

方法1 循环

public ListNode reverseList(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode now = head;
while (now.next != null) {
ListNode temp = now.next;
now.next = now.next.next;
temp.next = head;
head = temp;
}
return head;
}

方法2 递归

public ListNode reverseList2(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode newHead = reverseList2(head.next);
ListNode now =newHead;
while (now.next != null) {
now = now.next;
}
now.next = head;
head.next = null;
return newHead;
}

最新文章

  1. November 3rd Week 45th Thursday 2016
  2. PHP网页缓存技术
  3. Java for LeetCode 206 Reverse Linked List
  4. Python内置模块(2)
  5. win7录屏工具
  6. Java多线程之join
  7. Server Profiler
  8. AndroidRichText 让Textview轻松的支持富文本(图像ImageSpan、点击效果等等类似QQ微信聊天)
  9. [置顶] android 图片库的封装
  10. 安装Fedora(附镜像下载地址)
  11. mvn 使用中的错误
  12. bzoj2019 [Usaco2009 Nov]找工作
  13. 实现多条件模糊查询SQL语句
  14. .NET DateTime 源码学习
  15. 【爆料】-《南澳大学毕业证书》UniSA一模一样原件
  16. 【Ansible 文档】【译文】入门教程
  17. 【Spring学习笔记-MVC-10】Spring MVC之数据校验
  18. 深入理解MyBatis的原理:整个体系
  19. 使用Editplus和Dev C++配置C++的编译运行环 境
  20. iOS开发- 速学Swift-中文概述

热门文章

  1. Bloom 过滤器
  2. 查询GC日志、动态年龄计算
  3. Python杂章
  4. String与C风格字符串转换
  5. IBM DS5020 管理口密码重置
  6. windows pip使用国内源
  7. 017-zabbix_proxy分布式监控部署
  8. win10将mongodb加入系统服务,官方源码报错问题记录
  9. 牛客练习赛26 D xor序列 (线性基)
  10. Atcoder grand 025 组合数学塔涂色 贪心走路博弈