public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}
public ListNode ReverseList(ListNode head){
ListNode curr = new ListNode(-1);
curr.next = head;
ListNode next = head;
ListNode temp = head;
while (next.next!=null){
next = next.next;
temp.next = curr;
curr = temp;
temp = next;
}
next.next = curr;
head.next = null;
return next;
}