knakul853

Untitled

Jun 15th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. /**
  2. knakul853
  3. **/
  4. class Solution {
  5. public:
  6.     ListNode* reverseList(ListNode* head) {
  7.        
  8.         ListNode* pre=NULL ;   ///1->2->3->4
  9.         while(head)
  10.         {
  11.             ListNode* save_next = head->next;
  12.             head->next=pre;
  13.             pre = head;
  14.             head = save_next;
  15.         }
  16.         return pre; //(o(n) and o(1))
  17.        
  18.     }
  19. };
Add Comment
Please, Sign In to add comment