Advertisement
vaibhav1906

Reverse Linkedlist

Nov 29th, 2021
1,341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement