/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
if(head == null) {
return null;
}
ListNode dummy = new ListNode(-1);
dummy.next = head;
ListNode pre = dummy.next;
ListNode pCur = pre.next;
while(pCur != null){
pre.next = pCur.next;
pCur.next = dummy.next;
dummy.next = pCur;
pCur = pre.next;
}
return dummy.next;
}
}