public class Solution {
public ListNode ReverseList(ListNode head) {
if(head==null) {
return null;
}
ListNode newHead=null;
ListNode cur=head;
ListNode pre=null;
while(cur!=null) {
ListNode curNext=cur.next;
if(curNext==null) {
newHead=cur;
}
cur.next=pre;
pre=cur;
cur=curNext;
}
return newHead;
}
}