/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
// write code here
if(headnull){return null;}
if(head.nextnull){return head; }
ListNode prev=head;
ListNode cur=null;
while(prev!=null)
{ListNode prev_next=prev.next;
prev.next=cur;
cur=prev;
prev=prev_next;
}
return cur;
}
}