题目链接 这里
/**
* 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 null;
}
ListNode next=head.next;
ListNode pre=head;
ListNode temp;
head.next=null;
while(next!=null)
{
temp=next.next;
next.next=pre;
pre=next;
next=temp;
}
return pre;
}
}