/**
* Definition for ListNode.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int val) {
* this.val = val;
* this.next = null;
* }
* }
*/
public class Solution {
/*
* @param head: n
* @return: The new head of reversed linked list.
*/
public ListNode reverse(ListNode head) {
if(head==null){
return null;
}
ListNode q,p,k;
q=head.next;
p=head;
head.next=null;
while(q!=null){
k=q.next;
q.next=p;
p=q;
q=k;
}
return p;
}
}