/**
* 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) return head;
ListNode cur=head;
ListNode after=null;
ListNode temp;
while(cur!=null){
temp=cur.next;
cur.next=after;
after=cur;
cur=temp;
}
return after;
}
* 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) return head;
ListNode cur=head;
ListNode after=null;
ListNode temp;
while(cur!=null){
temp=cur.next;
cur.next=after;
after=cur;
cur=temp;
}
return after;
}
}
可以看看这篇博文http://blog.youkuaiyun.com/xudli/article/details/45715463