【小熊刷题】Reverse Linked List <Leetcode 206, Java>
2015-09-10 07:19
519 查看
Question
Reverse a singly linked list.*Difficulty: easy
https://leetcode.com/problems/reverse-linked-list/
没啥好说的,思路清楚就行,今儿可以洗洗睡了。
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode reverseList(ListNode head) { if(head == null || head.next == null) return head; ListNode curr = head; ListNode prev = null; while(curr != null){ ListNode next = curr.next; curr.next = prev; prev = curr; curr = next; } head = prev; return head; } }
相关文章推荐
- struts
- 【小熊刷题】Binary Search Tree Iteration <Leetcode 179, Java>
- Spring管理filter和servlet
- spring mvc的图片上传与显示
- java优先级队列调度
- 在java控制台中编写电话本,利用hashmap存储数据
- java 断言
- 配置Java开发环境
- eclipse properties 文件查看和编辑插件 Properties Editor
- 文件传输基础——Java IO流
- 实现二分法查找——java实现
- java初学环境变量的配置
- struts2标签库
- Spring+Mybatis+Maven+web整合
- spring事物和hibernate session提交小记
- Java任意同类型对象的复制
- spring 在web容器启动时执行初始化方法
- Spring security整合CAS单点登出的相关配置
- Spring中使用Map、Set、List、数组、属性集合的注入方法配置文件
- eclipse 安装svn插件