反转链表,用了一个比较笨的方法。

public class Solution {
public ListNode reverseList(ListNode head) {
if(head == null || head.next == null)
return head;
ArrayList<Integer> list = new ArrayList<Integer>();
ListNode p = head;
while(p!=null) {
list.add(p.val);
p = p.next;
}
ListNode q = head;
for(int i=list.size()-1; i>=0; i--) {
q.val = list.get(i);
q = q.next;
}
return head; }
}

LeetCode——Reverse Linked List的更多相关文章

  1. [LeetCode] Reverse Linked List 倒置链表

    Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either i ...

  2. [LeetCode] Reverse Linked List II 倒置链表之二

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  3. 【原创】Leetcode -- Reverse Linked List II -- 代码随笔(备忘)

    题目:Reverse Linked List II 题意:Reverse a linked list from position m to n. Do it in-place and in one-p ...

  4. [leetcode]Reverse Linked List II @ Python

    原题地址:https://oj.leetcode.com/problems/reverse-linked-list-ii/ 题意: Reverse a linked list from positio ...

  5. [LeetCode] Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  6. [LeetCode] Reverse Linked List

    Reverse a singly linked list. 这题因为palindrome linked list 的时候需要就顺便做了一下.利用三个指针:prev, now, next 相互倒腾就行. ...

  7. (leetcode)Reverse Linked List 脑子已经僵住

    Reverse a singly linked list. 参考http://www.2cto.com/kf/201110/106607.html 方法1: 讲每个节点的指针指向前面就可以. /** ...

  8. [Leetcode] Reverse linked list ii 反转链表

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given1->2 ...

  9. leetcode——Reverse Linked List II 选择链表中部分节点逆序(AC)

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...

  10. 翻转单链表 leetcode Reverse Linked List

    翻转一个单链表.这个题目听说很多次了,总感觉肯定不是什么难题. 现在真的有点好高骛远了!总感觉那种很难的算法题才是难题,这种题没必要做.其实眼高手低啊. 这种easy题,我都不能一遍ac,这遇到白板编 ...

随机推荐

  1. LUA中获得服务器IP

    local t = {} -- 引入相关包local socket = require("socket") function t.main() local a,b=pcall(t. ...

  2. /usr/include/glib-2.0/glib/gtypes.h:34:24: fatal error: glibconfig.h: No such file or directory

    cc -DDEBUG -mtune=core2 -O2 \ -onvideo nvideo.c \ -I/usr/include/atk-1.0 \ -I/usr/include/cairo \ -I ...

  3. Mac下面的SecureCRT(附破解方案) 更新到最新的7.2的破解方案

    继续更新到7.2的破解.只是升级了下secureCRT到7.2,方法还是不变 相信很多人升级到了7.2的SecureCRT之后原来的破解方案失效了,一直也有人问新的破解方案,发现了,不敢独享放上crt ...

  4. jquery方法操作iframe元素

    操作iframe父元素 $("#rolesCtl",parent.document).find( 'button' ).trigger( 'click' ); 在父页面获取ifra ...

  5. DataGridView使用技巧十一:DataGridView用户输入时,单元格输入值的设定

    通过DataGridView.CellParsing事件可以设定用户输入的值.下面的示例:当输入英文文本内容的时候,立即被改变为大写.DataGridView.CellParsing在离开编辑的单元格 ...

  6. Springboot 之 Hibernate自动建表(Mysql)

    Springboot 之 Hibernate自动建表(Mysql) 2016年10月21日 10:39:44 阅读数:8180 本文章来自[知识林] 引入Maven依赖包 <dependency ...

  7. css鼠标移动到文字上怎样变化背景颜色

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 让IE6支持min-height,max-height等的方法

    1.IE6支持max-height解决方法    IE6支持最大高度解决CSS代码:.yangshi{max-height:1000px;_height:expression((document.do ...

  9. WCF(二)

    摘自:http://www.cnblogs.com/yank/p/3666271.html WCF入门教程(二)从零做起-创建WCF服务 通过最基本的操作看到最简单的WCF如何实现的.这是VS的SDK ...

  10. 第二百九十一节,RabbitMQ多设备消息队列-安装与简介

    RabbitMQ多设备消息队列-安装与简介 RabbitMQ简介 解释RabbitMQ,就不得不提到AMQP(Advanced Message Queuing Protocol)协议. AMQP协议是 ...