vaibhav1906

Reverse Linkedlist

Nov 29th, 2021
929
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     ListNode* reverseList(ListNode* head) {
  4.         ListNode* prev = NULL;
  5.         ListNode* curr = head;
  6.         ListNode* next;
  7.        
  8.         while(curr!=NULL){
  9.             next = curr->next;
  10.             curr->next = prev;
  11.             prev= curr;
  12.             curr = next;
  13.         }
  14.        
  15.         return prev;
  16.     }
  17. };
RAW Paste Data