/**
* 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 || head.next == null){
return head;
}
ListNode pre = new ListNode (-1);
ListNode notIn = head;
while(notIn != null) {
ListNode tail = pre.next;
ListNode temp = notIn.next;
ListNode in = notIn;
in.next = tail;
pre.next = in;
notIn = temp;
}
return pre.next;
}
}