Reverse Linked List No 206

Java Solution

Posted by Captain Nimo 1 month ago

question

Reverse a singly linked list.

Code

 public ListNode reverseList(ListNode head){  
   ListNode prev=null;  
   while(head!=null){  
    ListNode temp=head.next;  
    head.next=prev;  
    prev=head;  
    head=temp;  
   }  
   return prev;  
 }