class Solution {
public ListNode reverseList(ListNode head) {
ListNode currentNode=head;
ListNode nextNode=null;
ListNode temp=null;
while(currentNode!=null){
temp=currentNode.next;
currentNode.next=nextNode;
nextNode=currentNode;
currentNode=temp;
}
return nextNode;
}
}
class Solution {
public ListNode reverseList(ListNode head) {
return reverseNode(null,head);
}
public ListNode reverseNode(ListNode nextNode, ListNode head){
if(head==null) return nextNode;
ListNode temp=null;
temp=head.next;
head.next=nextNode;
return reverseNode(head,temp);
}
}
class Solution {
public ListNode reverseList(ListNode head) {
if(head==null) return null;
if(head.next==null) return head;
ListNode nextNode=reverseList(head.next);
head.next.next=head;
head.next=null;
return nextNode;
}
}